I found this solution for the conditional display of the table. Please see below. How can I create a function to create tha rhandsom table and can be called from any reactive renderText context so that I do not have to reproduce the entire table's code every time I create a renderText context?
fname = tempfile(fileext = ".tsv")
observe({
input$saveBtn
hot = isolate(input$hot)
if (!is.null(hot)) {
write.table(hot_to_r(input$hot), fname)
print(fname)
}
})
output$hot = renderRHandsontable({
inFile = input$file
inFileName = input$file$name
result <- glycoPipe(inFileName)
if(result$validFile == FALSE){
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
DF = read.delim( "~/Development/Rand/glycoPipe_PARAMS_TEMPLATE.tsv", sep = '\t', stringsAsFactors = FALSE)
}
rhandsontable(DF) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE)
}
})
values <- reactiveValues()
data = reactive({
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
if (is.null(values[["DF"]]))
DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10],
dt = seq(from = Sys.Date(), by = "days", length.out = 10),
stringsAsFactors = F)
else
DF = values[["DF"]]
DF = read.delim("~/Development/Rand/glycoPipe_PARAMS_TEMPLATE.tsv", sep = '\t', stringsAsFactors = FALSE)
}
values[["DF"]] = DF
DF
})
output$hot <- renderRHandsontable({
inFile = input$file
inFileName = input$file$name
result <- glycoPipe(inFileName)
if(result$validFile == FALSE){
DF = data()
if (!is.null(DF)){
rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all")
}
}
})