Hi everyone, I am trying to figureout why my module is not responding to reactive data. I wrote a download handler module that that saves csv data where the data is reactive (foo_data()). I checked foo_data() changing based on my input values.
But, when I download the data, the csv (from foo_data()) was not updating.
downloadUI <- function(id,label.name) {
ns <- NS(id)
tagList(
p(strong(label.name)),
downloadButton(ns('down'), label='Download')
)
}
#' Server -----------------------
downloadServer <- function(id,out.data,file.name){
moduleServer(
id,
function(input, output, session){
output$down<- downloadHandler(
filename = function(){(paste0(file.name,'.csv'))},
content = function(file) {
write.csv(out.data,file,row.names = FALSE,na='')
}
)
} # End function
) # End moduleServer
} # End download Server
UI
downloadUI('Ref','Download Reference ')
Server
foo_data <- reactive({
.....
})
model_name <- reactive({
.....
})
output$Tbl_foo <- renderDataTable({foo_data()})
downloadServer('Ref',foo_data(), paste0('Sumdata_', model.name(),'_', Sys.Date()))
#--------------------------------------------------------------------------------------------------------
But when I wrote the downloadHander without using the module, the csv updates correctly corresponding to the foo_data().
# foo_data() updating correctly
ui:
downloadButton("download.sum", "Download")
Server:
output$download.sum <- downloadHandler(
filename = function() {
paste0('Sumdata_', model.name(),'_', Sys.Date(),'.csv')
},
content = function(file) {
write.csv(as.data.frame(foo_data()), file,row.names = FALSE,na='')
}
)
I can't figure out why my module is not reactive.