【问题标题】:R Shiny pickerInput select all textR Shiny pickerInput 选择所有文本
【发布时间】:2018-11-09 23:56:12
【问题描述】:

使用 shinywidgets pickerinput 我正在尝试使用下拉菜单。下面是代码。当用户选择所有输入时,有人可以告诉我如何在显示输入中显示文本总数。我可以显示计数,但不能显示文本总数。

library("shiny")
library("shinyWidgets")

ui <- fluidPage(
  column(
    width = 4,
    pickerInput(
      inputId = "id", label = "Choices :",
      choices = c("Banana", "Blueberry", "Cherry", "Coconut", "Grapefruit",
                  "Kiwi", "Lemon", "Lime", "Mango", "Orange", "Papaya"),
      options = list(`actions-box` = TRUE, `selected-text-format` = "count > 2",
                     `count-selected-text` = "{0}/{1} fruits"),
      multiple = TRUE
    )
  )
)


server <- function(input, output) {
  output$res <- renderPrint({
    input$id
  })
}

shinyApp(ui = ui, server = server)

【问题讨论】:

  • 在你的 ui 部分的某处添加textOutput("res")。除了pickerInput() 调用之外,您不会告诉您的应用显示任何内容。
  • 我想在选择选择器文本框(下拉菜单)内查看总计,而不是在外面查看。当您运行代码并选择无时,它表示没有选择任何内容。但是当它说选择总计时,它会显示单个项目而不是“总计”

标签: r shiny


【解决方案1】:

这样的?

编辑:根据要求I just want the text "TOTAL" when everything is selected

library("shiny")
library("shinyWidgets")

mychoices <- c("Banana", "Blueberry", "Cherry", "Coconut", "Grapefruit","Kiwi", "Lemon", "Lime", "Mango", "Orange", "Papaya")
ui <- fluidPage(
  column(
    width = 4,
    pickerInput(
      inputId = "id", label = "Choices :",
      choices = mychoices,
      options = list(`actions-box` = TRUE, `selected-text-format` = paste0("count > ", length(mychoices)),`count-selected-text` = "TOTAL"),
      multiple = TRUE
    )
  )
)


server <- function(input, output) {}

shinyApp(ui = ui, server = server)

【讨论】:

  • 如果我点击全选,我可以只显示总数而不是计数。
  • 请在那个领域画出你想要的东西
  • 从你放的图片中,我只想要选择所有内容时的文本“TOTAL”。
  • 我不确定你是如何让上面的代码工作的;我相信 paste0 有一个错字,并且永远不会出现计数大于可用选项总数的情况。但是对选项行的一些小修改对我有用。 options = list(`actions-box` = TRUE, `selected-text-format` = paste0("count &gt; ", length(mychoices) -1),`count-selected-text` = "TOTAL")
猜你喜欢
  • 2020-08-20
  • 2019-01-21
  • 2019-12-26
  • 1970-01-01
  • 2021-10-21
  • 2019-08-18
  • 1970-01-01
  • 1970-01-01
  • 2023-02-13
相关资源
最近更新 更多