我希望能够根据在单选按钮输入中所做的选择来更新 pickerInput 中可用的选择。在下面的示例中,我希望单选按钮“A”给出 mtcars$cyl 的 pickerInput 列表,而选择器输入“B”给出 mtcars$mpg 的选择器输入
我曾尝试使用 if 语句来执行此操作,但到目前为止我还没有得到任何结果。下面的可重现示例:
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)