【问题标题】:To allow multi select in Rhandsontable column dropdown允许在 Rhandsontable 列下拉列表中进行多选
【发布时间】:2018-09-13 14:10:34
【问题描述】:

我正在尝试在 R Shiny 中构建一个应用程序,我正在使用手动操作表来获取用户的输入。我的handsontable 中的一列有下拉列表,我需要用户进行多项选择。

例如,在我下面的示例代码中,我希望允许用户在“大”列中选择多个值(即用户应该能够为第一行选择 A、B、C,对于其他行也是如此)

library(shiny)
library(rhandsontable)

shinyApp(
  ui = fluidPage(
    fluidRow(
      column(12,
             sliderInput('input', label = "Rows",
                         min = 1, max = nrow(iris), value = 10)
      ),

      column(12
             ,
             rHandsontableOutput('table')
      )
    )
  ),
  server = function(input, output) {
    DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
                    small = letters[1:10],
                    dt = seq(from = Sys.Date(), by = "days", length.out = 10),
                    stringsAsFactors = FALSE)

    # try updating big to a value not in the dropdown
    output$table <- renderRHandsontable(
      rhandsontable(DF, rowHeaders = NULL, width = 550, height = 300) %>%
        hot_col(col = "big", type = "dropdown", source = LETTERS) %>%
        hot_col(col = "small", type = "autocomplete", source = letters,
                strict = FALSE)
    )
  }
)

如果有人遇到同样的问题并解决了同样的问题,请告诉我。

【问题讨论】:

    标签: drop-down-menu shiny multi-select handsontable rhandsontable


    【解决方案1】:

    您的问题对我来说有点令人困惑,您希望滑块对用户放置了多少个选定选项做出反应,或者...?

    那我不知道你为什么放 max = nrow(iris) 如果你不使用 iris 数据框,那是没有意义的。

    最后,如果你想要一个响应式 UI,那么当用户放置一些东西时,UI 会发生变化,你将需要这个:

    1- 服务器的反应函数:

    `outSli <- reactive({
     ##here you put your action
     })`
    

    2- 服务器改变ui滑块的观察功能:

    `observe({
     ##here you put the outSli() that contains your action or algorithm and then you update the slider
     updateSliderInput(session, "input", label = NULL, value = NULL,
      min = NULL, max = NULL, step = NULL)
     ##all those NULLs is what you change with your outSli()
     })`
    

    希望对你有帮助。

    【讨论】:

    • 感谢您的回复并为您的困惑道歉!实际上,问题与滑块无关,我只是希望用户能够在下拉列表中选择多个值。例如,在我的示例代码中,我希望允许用户在“大”列中选择多个值(即用户应该能够为第一行选择 A、B、C,对于其他行也是如此)。
    • 为此我认为你需要做 html 和 css
    • 是的,我想是的!但不确定,如何覆盖 Rhandsontable 的现有属性。可能是其他人可能有更好的主意。希望从 stackoverflow 用户那里得到一些东西。
    猜你喜欢
    • 2020-08-12
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-23
    • 2022-01-13
    • 2019-08-29
    • 2016-01-30
    相关资源
    最近更新 更多