[英]R Shiny: Conditionally require user to select pickerInput
I have two pickerInput
values in the app.我在应用程序中有两个
pickerInput
值。 In the first, geography
, the user can select to view either state
(default) or county
data.首先是
geography
,用户可以 select 查看state
(默认)或county
数据。 If the user selects county
, I'd like to require that they pick a state from the second pickerInput
, which is just a list of states.如果用户选择
county
,我想要求他们从第二个 pickerInput 中选择一个pickerInput
,这只是一个州列表。 It is not required that the user pick a state when input$geography == "state"
.当
input$geography == "state"
时,用户不需要选择 state。
I have considered putting this inside of a modalDialogue
but it wasn't working.我考虑过将它放在
modalDialogue
中,但它不起作用。 I also tried an updatePickerInput
which didn't work either.我还尝试了一个也不起作用的
updatePickerInput
。
What is the best way of conditionally requiring the user to select a value from a pickerInput
?有条件地要求用户 select 来自
pickerInput
的值的最佳方法是什么?
Thank you.谢谢你。
Here is a solution with shinyjs
:这是
shinyjs
的解决方案:
library(shiny)
library(shinyWidgets)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
pickerInput("pick_1", choices = c("state","county"), multiple = FALSE, selected = "state"),
shinyjs::hidden(
pickerInput("pick_2", choices = state.name, multiple = TRUE)
)
)
server <- function(input, output, session) {
observe({
toggleElement("pick_2", condition = input$pick_1 == "state")
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.