如果您使用下面的代码,可以看到它将有一个date
和两个selectInput
。例如,如果我在日历上选择了一个Sunday
,而在第二个selectInput
中已经选择了Morning
选项,那么是否可以不选中此选项,无论是与轮班还是与所选市场相关的选项?因此,这些选项将仅由用户选择。
library(shiny)
library(shinythemes)
library(lubridate)
df1<- structure(
list(
Marketname = c("Market1","Market1", "Market2","Market2", "Market3", "Market3"),
Days = c("Sunday","Sunday","Sunday","Sunday", "Sunday","Tuesday"),
Openinghours = c("Morning","Evening", "Morning","Evening","Evening","Evening")
), row.names = c(NA, 6L), class = "data.frame")
ui <- fluidPage(
shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
br(),
tabPanel("",
sidebarLayout(
sidebarPanel(
dateInput("date", "Which day shift do you choose?"),
selectInput("hours", label = h5("Which work shift do you choose??"), choices = NULL,
selected = ""),
selectInput("market", label = h5("Choose a market??"), choices = NULL,
selected = "")
),
mainPanel(
)
))
))
server <- function(input, output, session) {
week_day <- reactive({
wday(input$date, label = TRUE, abbr = FALSE)
})
observe({
updateSelectInput(session, "hours",
choices = unique(df1[df1$Days == week_day(), "Openinghours"])
)
})
observe({
updateSelectInput(session, "market",
choices = unique(df1[df1$Days == week_day() & df1$Openinghours %in% input$hours, "Marketname"])
)
})
}
shinyApp(ui = ui, server = server)
1条答案
按热度按时间anhgbhbe1#
不幸的是,
selectInput
默认显示第一个选项,但是在this answer之后的一个选项是使用selectizeInput
与multiple=TRUE
和options = list(maxItems = 1)
。