Hello Shiny folks!
I am super frustrated because I know I have solved this problem before but for whatever reason am having a devil of a time with it, I feel like I have tried everything and am out of ideas.
I have a modular/Golem Shiny app, where at one point I want to be able to click in a Reactable and have it pop up a modal with information about that row (i.e. set the "modalId" so to speak to be a component from that row).
I have successfully done this before several times but on a computer/code that I no longer have access to.
For whatever reason, I can't get ANY onClicks to work right now - I thought it might be a bootstrap thing, since the bootswatch theme I was using made a shinyWidgets::pickerInput not work at all, but even after getting rid of the theme it still doesn't work.
I have tried every way I possibly can in terms of getting the namespace to work, and nothing has worked - it seems like it isn't registering the click at all.
I am using logger to log input changes and when I click nothing happens at all, no matter what I do - even if I ignore the namespace and use a global variable (through sendCustomMessage)
Any ideas? I have been banging my head against this for 2 days now and feel like it has to be something really simple/stupid that I just keep not catching. I would appreciate any help, you'd be my hero! Thank you!
MVE is below, does this work for anyone else?:
mod_list_test_ui <- function(id){
ns <- NS(id)
tagList(
fluidPage(
# tried, doesn't work
# tags$head(
# tags$script(paste0('Shiny.addCustomMessageHandler("testmessage",
# function(message) {
# Shiny.setInputValue("',ns("foo"),'",message);
# }
# );'))
# ),
fluidRow(
shinyWidgets::pickerInput(inputId = ns("shinySelector2"),
label = "this works",
choices = c("woof","meow","beep"),
selected = "beep",
multiple = TRUE)
),
verbatimTextOutput(ns("fooOutput")),
reactableOutput(ns("tableInitial"))
)
)
}
mod_list_test_server <- function(id){
moduleServer( id, function(input, output, session){
ns <- session$ns
##tried, doesn't work
# session$sendCustomMessage(type = "testmessage",
# message = "initial")
#have tried every version of this - putting it inline, separately, ns, session$ns, no ns (master variable through the above), manually putting in the namespace - and no dice. have tried to get it to even just make a window alert or a console log and it won't do that either
jsCode <- paste0('function(rowInfo, column) {
Shiny.setInputValue("',ns("foo"),'","howdy");
};')
output$tableInitial <- renderReactable({
data.frame(animals = c("cow","pig","chicken"),
people = c("david","pete","bob"),
stringsAsFactors = F) %>%
reactable(
onClick = JS(jsCode)
)
})
output$fooOutput <- renderText({
if (is.null (input[["foo"]]) ){
"nothing"
}else{
input[["foo"]]
}
})
})
}