Home > Blockchain >  R shiny UI: how to make some inputs accessible/inaccessible with a checkbox or radio button?
R shiny UI: how to make some inputs accessible/inaccessible with a checkbox or radio button?

Time:01-05

I'm making an R shiny app to run some analyses. One section of the analysis is optional, and if it's included there are some parameters to choose. I'd like to design this into the shiny UI with a button ("Include optional analysis?") that if checked will let the user set the parameters they need. Any solution where the parameter inputs are inaccessible if the box isn't checked would work. For example if "Include optional analysis?" = False, maybe the parameter dropdowns are invisible, greyed out, or something similar.

How would I achieve this?

CodePudding user response:

This sounds like a job for conditionalPanel. Here is a simple application:

library(shiny)

ui <- fluidPage(
  sidebarPanel(
    checkboxInput("include", "Include Optional Analysis"),
    
    conditionalPanel(
      condition = "input.include",
      selectInput("breaks", "Breaks",
        c("Sturges", "Scott", "Freedman-Diaconis")
      ),
      selectInput("letters", "Letters", LETTERS))
  ),
  mainPanel()
)

server <- function(input, output) {}

shinyApp(ui, server)
  • Related