【问题标题】:Data validation when using rhandstable in Shiny在 Shiny 中使用 rhandstable 时的数据验证
【发布时间】:2018-01-01 16:31:32
【问题描述】:

我有以下 Shiny 应用程序来生成可编辑的表格。

library(shiny)

UI <- fluidPage(
  rHandsontableOutput('contents')
)
Server <- function(input, output) {

  list1 <- c("Bank", "Bank")
  list2 <- c("NA","NA")
  df <- data.frame(list1, list2)

  output$contents <- renderRHandsontable({
    rhandsontable(df)
  })

}

shinyApp(ui = UI, server = Server)

它工作正常。但是,我想包含一个下拉列表,我可以用它来替换值。所以假设我有一个这样的向量:

categories <- c("expenses", "income")

如何包含此内容,以便当我单击第二列中的单元格时,我有机会在费用和收入之间进行选择?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    如果您将df 定义为df &lt;- data.frame(list1, list2),则可以做到这一点

    output$contents <- renderRHandsontable({
      rhandsontable(df) %>% hot_col(col = 'list2', type = "dropdown", source = list2)
    
    })
    

    但是,这似乎只有在向量 list2 的长度大于 3 时才有效。

    【讨论】:

      猜你喜欢
      • 2018-04-25
      • 2023-04-02
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2014-10-04
      • 2023-04-10
      • 2015-03-08
      相关资源
      最近更新 更多