OK, you can classify conditional inputs in two categories.
1) , ui.R( checkboxInput)
2) , .R( )
:
1), renderUI(), . .
2), , .R, JS- ui.R. 1) , , , , 2).
:
"checkbox" boolean: false. "typeInput" ( "checkbox" ). , "typeInput" null.
, "typeInput" , ,
"typeInput" , , .
"typeInput" , :
if(!is.null(input$typeInput)) , "typeinput" ( : , "" ).
ui <- fluidPage(
titlePanel("BC Liquor Store prices"),
img(src = "BCLS.png",align = "right"),
sidebarLayout(
sidebarPanel(sliderInput("priceInput", "Price", 0, 100, c(25, 40), pre = "$"),
wellPanel(
checkboxInput("checkbox", "Filter by Type", FALSE),
uiOutput("conditionalInput")
),
uiOutput("countryOutput")
),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotOutput("coolplot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("results"))
)
)
)
)
server <- function(input, output, session) {
output$countryOutput <- renderUI({
selectInput("countryInput", "Country",
sort(unique(bcl$Country)),
selected = "CANADA")
})
output$conditionalInput <- renderUI({
if(input$checkbox){
selectInput("typeInput", "Product type",
choices = c("BEER", "REFRESHMENT", "SPIRITS", "WINE"),
selected = "WINE")
}
})
filtered <- reactive({
if (is.null(input$countryInput)) {
return(NULL)
}
bcl %>%
filter(Price >= input$priceInput[1],
Price <= input$priceInput[2],
Type == input$typeInput,
Country == input$countryInput
)
})
output$coolplot <- renderPlot({
if (is.null(filtered())) {
return()
}
filtered() %>% ggvis(~Alcohol_Content, fill := "#fff8dc") %>%
layer_histograms(width = 1, center = 0)
})
output$results <- renderTable({
filtered()
})
}
shinyApp(ui = ui, server = server)