I am dynamically generating an unknown number of rhandsontable by querying the databased and rendering them using renderUI.
However, I can't find a way how to consume these tables after user might have made some modification on them since there's no input ID field in them. Can a custom ID be assigned to a rhandsontable using which we can get it's contents later?
Many thanks! Here's code to reproduce the issue. I'm generating some tables, and clicking on button once page has rendered will help browse where we can test variables using input$ etc.
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)