onclick() does not work for element in renderUI in shiny > 1.7.5
moturoa opened this issue · 6 comments
With the latest shiny update (1.7.5, also tested dev version 1.7.5.900), shinyjs::onclick
again does not work for elements generated in renderUI
This was the case in 2015 and then fixed. We now see the problem again. The following works in shiny 1.7.4.1, not in > 1.7.5.
Although this is not a shinyjs bug per se, I figured I should post it here. Probably something to do with the new async dynamic UI in shiny 1.7.5.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
uiOutput("ui1")
)
server <- function(input, output, session) {
output$ui1 <- renderUI({
selectInput("sel_test","Test", choices = LETTERS[1:10])
})
shinyjs::onclick("sel_test", {
print("SELECT CLICKED")
})
}
shinyApp(ui, server)
I'm not on a computer yet so can't check it out, but if this is true that sounds like it'll be an annoying bug to fix! Can you show me the bug report from 2015 you're referring to?
Ah, that issue existed in 2015 just because I never implemented it before that point. From my testing so far, you seem to be right, that shiny 1.7.5 broke this likely because of a different way dynamic UI is rendered. I'm trying to look into it but I might end up having to post an issue on shiny. Thanks for raising.
Found the issue. When a new selectize element is added to the page, previously it had a class of shiny-bound-input
which was a way to identify that it's a shiny input. Since version 1.7.5, that class does not exist initially and it only gets added after the javascript for the selectize finishes rendering it. Other inputs (such as textInput) will still work, I think this issue will only affect dynamically rendered complex inputs. I can't think of a clean way to handle the new shiny code because there is no indication in the DOM that the element is an input, so I'm going to post it as a bug in the shiny repo.
@moturoa I think I found a fix. Can you try installing the latest shinyjs from github and verify that it works for you?
Thanks for the fix; this does solve the actual problem (in the above test and also in one of our apps where this is a real problem).