【问题标题】:Create a selectInput() with maximum number of choices based on a numericInput()基于 numericInput() 创建一个具有最大选择数的 selectInput()
【发布时间】:2018-07-19 19:58:06
【问题描述】:

我有一个简单的闪亮应用:

#ui.r
navbarPage(
  "Application",
  tabPanel("General",
           sidebarLayout(

             sidebarPanel(
               uiOutput("book1")
             ),
             mainPanel(
               uiOutput("book10")
             )
           )))
#server.
library(shiny)
library(DT)
server <- function(input, output,session) {
  output$book1<-renderUI({
    numericInput("bk1", 
                 "Items in test", 
                 value = 1,
                 min = 1)
  })
  output$book10<-renderUI({

    selectInput("bk10", 
                "Select Items", 
                choices=1:10000,multiple =T,selected = 1)
  })
}

在边栏中,我有一个numricInput(),我想将其用作主面板中selectInput() 中显示的选项数量的限制。例如,如果 numericImput() 设置为 5,则 selectInput() 可能只显示 5 个选项,例如:21,22,23,45,67。

【问题讨论】:

  • 对不起,我编辑了。它的 5。基本上这是由 numericInput 设置的。数字是随机的。

标签: r shiny


【解决方案1】:
server <- function(input, output,session) {
        output$book1<-renderUI({
          numericInput("bk1", 
                       "Items in test", 
                       value = 1,
                       min = 1)
        })

        output$book10<-renderUI({
          selectizeInput(
            "bk10", "Max number of items to select", choices =1:1000,multiple =T,selected = 1,
            options = list(maxItems = input$bk1))
          #selectizeInput(
          #  "bk10", "Select Items", choices =1:1000,multiple =T,selected = 1,
          #  options = list(maxOptions = input$bk1))
        })

      }

更多选项,您可以查看here。希望对你有帮助。

【讨论】:

  • 不完全是,我希望 numericInput 设置 selectInput() 可以显示的最大选项数。如果设置为 5,则 selectInput 最多可以显示 5 个选项,例如随机 10、34、56、78、67。
  • 它产生随机数。例如,我使用了随机数。我的选择应该是从 1 到 10000,但应该只显示数字集。如果这个数字是 10,它们可能是从 1 到 10,或 30 到 40 或 10 个随机数字,我将按照我之前提到的那样选择。
  • 我仍然可以选择 10 多个选项。我不确定我所问的是否可能。
  • 所以你有例如100 个选项,但您想限制用户仅选择 5 个或作为用户输入 numericInput
  • 就是这样!tnx 很多!
猜你喜欢
  • 2021-01-22
  • 2017-10-19
  • 1970-01-01
  • 2021-05-17
  • 2021-04-22
  • 1970-01-01
  • 2014-06-19
  • 2016-09-24
  • 1970-01-01
相关资源
最近更新 更多