首页 > 解决方案 > 如何在另一个 ui pickerInput 选项中使用数字输入?

问题描述

在闪亮中,我需要选择一个数字范围并将其用作另一个选择器输入中的选择。

首先我有:

               sliderTextInput(
                inputId = "size.range",
                label = "Choose a value:", 
                choices = c(1:100),
                selected =c(18,24),
                grid = TRUE )

在我拥有之后:

                      pickerInput(
                       inputId = "sample.histoall",
                       label = "Selected Size",
                       choices = list( XXXXXX ),
                       options = list(`actions-box` = TRUE),
                       multiple = TRUE)

我用什么替换 XXXXXX ?

标签: rshiny

解决方案


您可以观察数值范围的值并pickerInput在每次更改时更新您的值。您可以选择在您的pickerInput. 我在下面的示例中添加了这两个选项。

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  sliderTextInput(
    inputId = "size.range",
    label = "Choose a value:", 
    choices = c(1:100),
    selected =c(18,24),
    grid = TRUE ),
  pickerInput(
    inputId = "sample.histoall",
    label = "Selected Size",
    choices = list( '' ),
    options = list(`actions-box` = TRUE),
    multiple = TRUE),
  pickerInput(
    inputId = "sample.histoall.range",
    label = "Selected Size",
    choices = list( '' ),
    options = list(`actions-box` = TRUE),
    multiple = TRUE)
)

server <- function(input, output, session) {
  observe({
    updatePickerInput(session, 'sample.histoall', choices=input$size.range)
    updatePickerInput(session, 'sample.histoall.range', choices=as.numeric(input$size.range[1]):as.numeric(input$size.range[2]))
  })
}

shinyApp(ui, server)

推荐阅读