Avoid flashing of UI elements placed in a conditionalPanel on app start

Coming from here.

When buttons and other UI elements are placed in a conditionalPanel which on app/session start should prevent displaying those elements, they are sporadically flashing for a very short time.

I tried to workaround this behaviour by including typeof input.yourChoice !== 'undefined' into the condition, but it doesn't help.

MWE to reproduce the problem:

library(shiny)

ui <- fluidPage(
  radioButtons("yourChoice", "Display button?", choices = c("Yes", "No"), selected = "No",),
  conditionalPanel("input.yourChoice == 'Yes'", actionButton("test", "test"))
  
  # not working: ------------------------------------------------------------
  # conditionalPanel("typeof input.yourChoice !== 'undefined' && input.yourChoice == 'Yes'", actionButton("test", "test"))
  # conditionalPanel("typeof input !== 'undefined' && input.yourChoice == 'Yes'", actionButton("test", "test"))
)

server <- function(input, output, session) {}

shinyApp(ui, server)

Animation

I'm looking for a base shiny / JS UI based solution - no renderUI or server based workarounds.

By now I got some feedback on GitHub.

The flashing can be avoided by setting style = "display: none;":

library(shiny)

ui <- fluidPage(
  radioButtons("yourChoice", "Display button?", choices = c("Yes", "No"), selected = "No",),
  conditionalPanel("input.yourChoice == 'Yes'", style = "display: none;", actionButton("test", "test"))
)

server <- function(input, output, session) {}

shinyApp(ui, server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.