I want to be able to update the selection available in the pickerInput based upon the selection made in the radio button input. In the example below, I want the radio button "A", to give a pickerInput list of mtcars$cyl, whilst a picker input of "B" to give a picker input of mtcars$mpg
I have tried doing this using if statements, but I haven't got anywhere so far. Reproducible example below:
library(shiny)
library(leaflet)
library(shinyjs)
library(rgeos)
library(tidyverse)
library(openxlsx)
library(plotly)
library(shinyWidgets)
library(rgdal)
ui <- fluidPage(shinyjs::useShinyjs(),
fluidRow(column(
6,radioButtons("type", "Type:",
c("A" = "norm",
"B" = "unif")))),
fluidRow(column(
3,
pickerInput("regInput","Region",choices=unique(mtcars$cyl),
options = list(`actions-box` = TRUE),multiple = T,
selected = unique(mtcars$cyl)))))
server <- function (input, output, session) {
observeEvent(input$type,{
a_option <- input$regInput
if (a_option == "B") {
updatePickerInput(session = session,inputId = "regInput",
choices =unique(mtcars$mpg))}})
}
shinyApp(ui = ui, server = server)