daattali / shinyjs

💡 Easily improve the user experience of your Shiny apps in seconds
https://deanattali.com/shinyjs
Other
728 stars 119 forks source link

Cannot hide/ show/ toggle fields in shiny Modal #225

Closed alon-sarid closed 3 years ago

alon-sarid commented 3 years ago

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)`

daattali commented 3 years ago

It doesn't look like you loaded shinyjs. useShinyjs()

On Sun., Dec. 20, 2020, 04:25 alon-sarid, notifications@github.com wrote:

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)

`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/daattali/shinyjs/issues/225, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHIQFFIMZUCN3ESY3BSZADSVW7HFANCNFSM4VC6KIVA .

alon-sarid commented 3 years ago

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)`