-
Notifications
You must be signed in to change notification settings - Fork 132
Add shiny inputs #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add shiny inputs #86
Conversation
| paste("You clicked on topic:", input$ldavis_topic_clicked) | ||
| ) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the observe() blocks here, I'd prefer to see:
output$topicClicked <- renderPrint({
if (is.null(input$ldavis_topic_clicked)) return()
paste("You clicked on topic:", input$ldavis_topic_clicked)
})| // update shiny inputs to be null | ||
| Shiny.onInputChange('ldavis_topic_clicked', null); | ||
| Shiny.onInputChange('ldavis_term_clicked', null); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested this functionality outside of a shiny context? I think this would throw an error since Shiny is not defined if it's not running in a shiny app. In that case, we should add a check to see if we're in shiny mode similar to how HTMLwidgets does it -- https://github.com/ramnathv/htmlwidgets/blob/master/inst/www/htmlwidgets.js#L15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't..I'll add a check like the one you describe before calling onInputChange().
|
Thanks @crew102, this is looking great! As long as you address my small comments, this is very close to getting a 👍 from me, but I also wait to see if @kshirley has any feedback before merging...
I very much agree, and have a feeling @kshirley would as well. Any idea how hard it would be to implement? If it isn't super difficult, I may insist on it since our general philosophy has been that clicking on a topic yields the same behavior as flipping through them via the input buttons. |
It's actually easy. I'll resubmit with it implemented. Also there was a small bug in this version of the PR where clicking on a topic, clearing the vis, then clicking on that same topic again was not resulting in the topic's border being bolded. I've fixed this. |
04c87ee to
f8db5e8
Compare
… shiny's input object (closes cpsievert#45)
… and input$ldavis_topic_clicked
f8db5e8 to
456aac7
Compare
|
OK, I think this should be all set now. I was having some git difficulties but I think this should do it. |
|
Sorry, I just thought of this, but it seems like we should only modify the stroke/underline when in shiny mode. Otherwise, it might be confusing as to why terms are getting underlined on click (when, outside of shiny mode, it doesn't really do anything) So, instead of checking for topic_click = function(newtopic, newtopic_num) {
if (inShinyMode) {
return null;
}
...
} |
|
Sure, that makes sense. |
|
|
||
| // update shiny input$ldavis_topic_clicked object to be new topic clicked | ||
| Shiny.onInputChange('ldavis_topic_clicked', newtopic_num); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the input name should have information about the relevant outputId (so, on the server, you can listen/respond to events from a specific output). Ideally the API would work like leaflet, but I'm not immediately sure how to implement, any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be easy, as the outputId gets passed into the LDAvis code as a selector here:
LDAvis/inst/shiny/shinyLDAvis.js
Lines 13 to 14 in bdd7b01
| var to_select = "#" + el.id; | |
| var vis = new LDAvis(to_select, json_file); |
Note that we would need #39 to be merged to allow handling multiple ldavis outputs in the same app.
I'll change the API as you suggested, and whenever #39 is merged than having the outputIds in the input names will come in handy.
| var outputId = to_select.substring(1, to_select.length); | ||
| var topicClicked = outputId + "_topic_click"; | ||
| var termClicked = outputId + "_term_click"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! I'd prefer more descriptive variable names here, say shinyClickedTopic/shinyClickedTerm
Once that's done, this looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
|
Just to chime in: this feature sounds good and from the discussion it looks like you two are covering all the bases. I give it my thumbs-up when complete. Looking forward to trying it out. Thanks for contributing @crew102 ! And thanks as always for the leadership and responsiveness, @cpsievert . |
baa7667 to
a03d4e2
Compare
|
@crew102 one last thing if you'd like -- update the NEWS file and add yourself as a contributor in the DESCRIPTION 😃 |
|
Hey @cpsievert , I tried to follow the style that I found in NEWS, but I could have gotten it wrong. Also, I incremented the version to 0.3.5. |
Hey @cpsievert , this PR addresses the issues discussed in #45. Specifically, it:
inputobject to know about clicks to the terms/topics. I decided not to not link hover events to the shinyinputobject.A few notes regarding the behavior of
input$ldavis_term_clickedandinput$ldavis_topic_clicked:ldavis_term_clickedis reset to null wheneverldavis_topic_clickedchangesldavis_term_clickedandldavis_topic_clickedgoing to nullldavis_topic_clickedcan be null andldavis_term_clickednon-null is when viewing the marginal distribution (i.e., when no topic is selected)ldavis_topic_clicked. In other words, you have to actually click on a topic (or reset the vis) to changeldavis_topic_clicked.The first three items describe desired behavior from my perspective (in other words, this was what I was going for). Ideally the topic input object would change
ldavis_topic_clicked, but I didn't have time to implement it so...