【发布时间】:2021-12-28 19:56:10
【问题描述】:
我通过查询数据库并使用 renderUI 渲染它们来动态生成未知数量的 rhandsontable。
但是,由于其中没有输入 ID 字段,因此在用户可能对它们进行了一些修改后,我找不到如何使用这些表的方法。可以将自定义 ID 分配给 rhandsontable,以便我们稍后获取它的内容吗?
非常感谢!这是重现该问题的代码。我正在生成一些表格,并在页面呈现后单击按钮将有助于浏览我们可以使用 input$ 等测试变量的位置。
library(shiny)
library(rhandsontable)
library(shinyWidgets)
ui <- fluidPage(
fluidRow(
uiOutput('test'),
actionBttn(
inputId = "Id107",
label = "button",
style = "unite",
color = "danger"
)
)
)
server <- function(input, output, session) {
var1 <-c(1,2,3)
var2 <-c('X','Y','Z')
var3 <-c('Sample1','Sample2')
observeEvent(input$Id107,{
browser()
})
output$test = renderUI({
table_names<-c('Alpha', 'Beta', 'Gamma')
t<- matrix(data = 0, nrow = length(var2), ncol = length(var1)) %>%
`rownames<-`(c(var2)) %>%
`colnames<-`(c(var1))
t1<-t
t2<-t
input_list <- lapply(1:length(var3), function(i) {
new_list <- lapply(1:length(table_names),function(j) paste(var3[i] ," ", table_names[j], sep = "") )
list(
column(12,
column(5,align='left',withTags(div(h5(b(new_list[1]))))),
column(4,align='left',withTags(div(h5(b(new_list[2]))))),
column(3,align='left',withTags(div(h5(b(new_list[3]))))),
),
column(12,
column(5,div(id = gsub("[^[:alnum:]]", "_", new_list[1]),renderRHandsontable(
rhandsontable(t, overflow='hidden',maxRows=nrow(t), minRows=nrow(t)) %>%
hot_validate_numeric(c(1:ncol(t))) %>%
hot_table(stretchH = "all") %>%
hot_col(c(1:ncol(t)),format = "$0,0")))
),
column(4,div(id = gsub("[^[:alnum:]]", "_", new_list[2]),renderRHandsontable(#
rhandsontable(t1, overflow='hidden',maxRows=nrow(t1), minRows=nrow(t1)) %>%
hot_validate_numeric(c(1:ncol(t1))) %>%
hot_table(stretchH = "all") %>%
hot_col(c(1:ncol(t1)),format = "0.00%")))
),
column(3,div(id = gsub("[^[:alnum:]]", "_", new_list[3]),renderRHandsontable(#
rhandsontable(t2, overflow='hidden',maxRows=nrow(t2), minRows=nrow(t2)) %>%
hot_validate_numeric(c(1:ncol(t2))) %>%
hot_table(stretchH = "all") %>%
hot_col(c(1:ncol(t2)),format = "0")))
)
)
)
})
do.call(tagList,input_list)
})
}
shinyApp(ui, server)
【问题讨论】:
-
我知道这个包的大部分组件都是基于handsontable的,显然有一个ID列,但我似乎无法在任何地方使用它handsontable.com/docs/vue-custom-id-class-style
-
this thread 怎么样?如果这没有帮助,您能否发布一个简单的示例以便更轻松地重现您的问题?
-
感谢您的回复。在共享的链接中,表“热”的名称是已知的,因此可以引用。我更新了生成一些表的代码,但每个 rhandsontable 的 ID 是未知的-感谢任何帮助
标签: r rhandsontable