-
Notifications
You must be signed in to change notification settings - Fork 633
event_data not working for Shiny Modules? #659
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
Comments
I have the same issue but its interesting to note that an Here's an example - library(plotly)
library(shiny)
plotlyUI <- function(id){
ns <- NS(id)
plotlyOutput(ns("plotlyout"))
}
plotlyModule <- function(input, output, session){
output$plotlyout <- renderPlotly(
plot_ly(x = 1:100, y = (1:100), mode = "lines + markers")
)
}
ui <- fluidPage(
plotlyUI("plotlytest1"),
plotlyUI("plotlytest2"),
verbatimTextOutput("text")
)
server <- function(input, output, session){
callModule(plotlyModule, "plotlytest1")
callModule(plotlyModule, "plotlytest2")
output$text <- renderPrint(
event_data("plotly_click")
)
}
shinyApp(ui, server) |
I think such behavior is actually very dangerous for modular design. library(plotly) plotlyUI <- function(id){ plotlyModule <- function(input, output, session){ plotlyUI2 <- function(id){ plotlyModule2 <- function(input, output, session){ ui <- fluidPage( server <- function(input, output, session){ output$text <- renderPrint( shinyApp(ui, server) |
Outside of allowing The
|
@charleyferrari my expectation of using the event_data is to be inside the module. This is because I need the interaction to exist strictly inside that module. My goal is to develop hundreds of modules and not have to worry about naming collision and the source of the event_data |
@cpsievert , could you confirm once crosstalk is more mature it would work in module namespace? My use case for using plotly in modules is:
Please let me know if I need to clarify further. |
I can't speak for the package author, but considering crosstalk and shiny have the same author, it is very likely ;) Feel free to experiment by installing the pull request and perusing the examples (as a word of warning though, things will change, but will also become more stable over the coming weeks). devtools::install_github("rstudio/crosstalk")
devtools::install_github("ropensci/plotly#554") |
I just wrapped the shiny example into the module.
|
I'll try to reach Joe on this topic and update you guys later. |
@happyshows -- Did you receive any feedback from Joe on this? We are trying to get this resolved for you and I want to make sure I have all relevant info as to the status. |
Hi Rob, Here's the latest comment I received from Joe: I'm a bit bummed at how long it will take the community to align around crosstalk, even for just rbokeh and plotly, but this is delicate work that requires a bunch of people to share the same mental model, which hasn't quite happened yet. |
@happyshows do you have any availability today for a call? I am trying to get one our engineers involved to make sure we are doing everything we can to help you get what you need |
@happyshows rstudio/shiny#1343 should give me the tools I need to make this possible. Until that happens, this would be my suggested way to accessing (namespaced) event data: library(shiny)
library(plotly)
reusableUI <- function(id = NULL) {
ns <- NS(id)
fluidPage(
plotlyOutput(ns("p")),
verbatimTextOutput(ns("ev"))
)
}
reusableScatter <- function(input, output, session, source, event) {
output$p <- renderPlotly({
plot_ly(mtcars, x = ~mpg, y = ~disp,
key = row.names(mtcars), source = source) %>% add_markers()
})
output$ev <- renderPrint({
event()
})
}
ui <- fluidPage(
reusableUI("myLargeApp")
)
server <- function(input, output, session) {
hover <- reactive(event_data("plotly_hover", source = "A"))
callModule(
reusableScatter, "myLargeApp", session = session, source = "A", event = hover
)
}
shinyApp(ui, server) |
thanks for the follow up. I'll watch that thread and see how things go. Hopefully the new solution will work with my 'nested module' design - that's also why I prefer not to use the source approach, as each module may be called multiple times with different parameters in the same panel. You also mentioned earlier about deprecating the event_data, will that still be the goal once the rstudio/shiny#1343 is completed? |
No, |
@charleyferrari ^^ how does this relate to what Shows at AMD brought up today? |
The latest dev release closes this issue |
Hi,
I tried a couple combinations but couldn't get it to work, please advise:
`
library(shiny)
library(shinyBS)
library(plotly)
Module.testUI <- function(id){
ns <- NS(id)
plotlyOutput(ns('ply_main'))
}
Module.test <- function(input, output, session, sess) {
ns <- session$ns
output$ply_main <- renderPlotly({
df1 <- data.frame(x = 1:10, y = 1:10)
plot_ly(df1, x = ~x, y = ~y) %>% add_markers()
})
observe({
# eventdata <- event_data(ns('plotly_click'))
eventdata <- event_data('plotly_click',source = ns('ply_main'))
# eventdata <- event_data('plotly_click')
isolate({
print(eventdata)
})
})
}
ui <- fluidPage(
tagList(
Module.testUI('test'),
Module.testUI('test2')
)
)
server <- function(input, output) {
callModule(Module.test,'test', sess)
callModule(Module.test,'test2', sess)
}
shinyApp(ui = ui, server = server)
`
The text was updated successfully, but these errors were encountered: