Не можете увидеть условный выбор в Shiny MainPanel? - PullRequest
1 голос
/ 29 марта 2020

Я пытаюсь разрешить пользователю выбирать из различных опций, но по какой-то причине я не вижу опций в своей главной панели:

ui <- fluidPage(
  h1("Reminder to do X"),
  sidebarLayout(
    sidebarPanel(
      radioButtons(
        inputId = "type",
        label = "Reminder Type",
        choices = c("Single Date Reminder" = "single",
                    "Multi Date Reminder" = "multi",
                    "From-To Reminder" = "from_to"),
        selected = "single", width = '100%'
      )
    ),
    mainPanel(
      conditionalPanel(
        condition = "input.source == 'single'",
        dateInput("single_date", "Enter the date for your reminder", value = Sys.Date())
      ),
      conditionalPanel(
        condition = "input.source == 'multi'",
        dateRangeInput("multi_date_1", 
                       label = "Enter from to dates", 
                       start = Sys.Date(), 
                       end = Sys.Date() + 7,
                       autoclose = TRUE)
      ),
      conditionalPanel(
        condition = "input.source == 'from_to'",
        dateRangeInput("multi_date_2", 
                       label = "Enter from to dates", 
                       start = Sys.Date(), 
                       end = Sys.Date() + 7,
                       autoclose = TRUE)
      )
    )
  )
)

  shinyApp(ui, server = function(input, output) { })

Пожалуйста, посоветуйте, как я могу увидеть выбранную опцию выбора даты? Я нажимаю кнопку радио, но не вижу средства выбора даты.

enter image description here

1 Ответ

2 голосов
/ 29 марта 2020

Это связано с неправильной ссылкой на идентификатор. Ваш inputiD равен "type", а в вашем conditionalPanel() вы ссылаетесь на "source". Поэтому измените все input.source на input.type, и это будет работать.

Итак, ваш код выглядит следующим образом:

ui <- fluidPage(
  h1("Reminder to do X"),
  sidebarLayout(
    sidebarPanel(
      radioButtons(
        inputId = "type",
        label = "Reminder Type",
        choices = c("Single Date Reminder" = "single",
                    "Multi Date Reminder" = "multi",
                    "From-To Reminder" = "from_to"),
        selected = "single", width = '100%'
      )
    ),
    mainPanel(
      conditionalPanel(
        condition = "input.type == 'single'",
        dateInput("single_date", "Enter the date for your reminder", value = Sys.Date())
      ),
      conditionalPanel(
        condition = "input.type == 'multi'",
        dateRangeInput("multi_date_1", 
                       label = "Enter from to dates", 
                       start = Sys.Date(), 
                       end = Sys.Date() + 7,
                       autoclose = TRUE)
      ),
      conditionalPanel(
        condition = "input.type == 'from_to'",
        dateRangeInput("multi_date_2", 
                       label = "Enter from to dates", 
                       start = Sys.Date(), 
                       end = Sys.Date() + 7,
                       autoclose = TRUE)
      )
    )
  )
)

shinyApp(ui, server = function(input, output) { })

И вывод:

enter image description here

ОБНОВЛЕНИЕ

Я немного изменил ваш код и включил один пример airDatepickerInput(). Поэтому я изменил эту часть вашего кода

     conditionalPanel(
        condition = "input.type == 'multi'",
        dateRangeInput("multi_date_1", 
                       label = "Enter from to dates", 
                       start = Sys.Date(), 
                       end = Sys.Date() + 7,
                       autoclose = TRUE)
)

На эту

 conditionalPanel(
        condition = "input.type == 'multi'",
        airDatepickerInput(
          inputId = "multiple",
          label = "Select multiple dates:",
          placeholder = "You can pick 3 dates",
          multiple = 3, clearButton = TRUE
        )
      )

И это вывод:

enter image description here

Обратите внимание, что если вы также хотите выбрать время, вставьте timepicker = TRUE внутри airDatepickerInput()

...