Hi everyone! I'm trying to use shinyjs
to disable a button inside a child module whose id comes from a parent module but even with namespacing this doesnt seem to work - I put the three files here if anyone has time to take a look! Maybe this is because the dom element isn't loaded prior to the JS code? Can I somehow force the module elements to exist when rendering them in the server?
app.R calls parent module
library(shiny)
source("parent_module.R")
source("child_module.R")
ui <- fluidPage(
parent_mod_ui("parent")
)
server <- function(input, output) {
callModule(parent_mod_srv, "parent")
}
shinyApp(ui = ui, server = server)
parent_module.R creates a modal with a close button
parent_mod_ui <- function(id) {
ns <- NS(id)
actionButton(ns("click_me"), "CLICK ME")
}
parent_mod_srv <- function(input, output, session) {
ns <- session$ns
observeEvent(input$click_me, {
showModal(
modalDialog(
title = "This is a modal",
footer = actionButton(ns("toggle_disable"), "CLOSE MODAL"),
child_mod_ui(ns("child"))
)
)
})
observeEvent(input$click_me, {
callModule(child_mod_srv, "child")
})
observeEvent(input$toggle_disable, {
removeModal()
})
}
child_module.R conditionally disables the close button
child_mod_ui <- function(id) {
ns <- NS(id)
tagList(
sliderInput(ns("the_slider"), "SLIDE", min = 0, max = 10, value = 3)
)
}
child_mod_srv <- function(input, output, session) {
ns <- session$sn
observeEvent(input$the_slider, {
if (input$the_slider > 5) shinyjs::disable("parent-toggle_disable")
})
}