daattali/shinyjs

Cannot hide/ show/ toggle fields in shiny Modal

alon-sarid opened this issue · 2 comments

Hi.

I wish to hide show relevant UI items inside a popout modal, based on the selection of other fields within the modal.
yet shinyjs::hide.shinyjs::show and toggle does not work

example code:

`library(shiny)

ui <- fluidPage(
actionButton("show_modal", "show modal"),
)

server <- function(input, output) {

observeEvent(input$show_modal, {

showModal(
  
  modalDialog(footer = NULL,easyClose = T,
              
              tagList(
                
                fluidRow(
                
                box(status = "primary", width = 6, style = "direction: ltr",
                    
                    actionButton("toggle_btn", "show or hide second button")
                    
                    
                    )),
                
                fluidRow(
                  
                box(status = "success", width = 6, style = "direction: ltr",
                    
                    
                    actionButton("box_btn", "btn!")
                    
                    
                ))
                
                
              )
  ))

})

observeEvent(input$toggle_btn, {

shinyjs::toggle("box_btn")
cat("\npresentation button pressed\n")

})

}

shinyApp(ui, server)`

Thanks!
I am sorry for wasting your time.

this works now:

` library(shiny)
library(shinyjs)

ui <- fluidPage(
useShinyjs(),
actionButton("show_modal", "show modal"),
)

server <- function(input, output) {

observeEvent(input$show_modal, {

showModal(
  
  modalDialog(footer = NULL,easyClose = T,
              
              tagList(
                
                fluidRow(
                
                box(status = "primary", width = 6, style = "direction: ltr",
                    
                    actionButton("toggle_btn", "show or hide second button")
                    
                    
                    )),
                
                fluidRow(
                  
                box(status = "success", width = 6, style = "direction: ltr",
                    
                    
                    actionButton("box_btn", "Box!")
                    
                    
                ))
                
                
              )
  ))

})

observeEvent(input$toggle_btn, {

shinyjs::toggle("box_btn")
cat("\npresentation button pressed\n")

})

}

shinyApp(ui, server)`