Lavoro su una lunga app Shiny in cui voglio dare la possibilità all'utente di salvare l'input in un file Rdata per caricarlo dopo.Salva l'input nel file per continuare in un'altra sessione l'analisi dei dati in R Shiny App
riesco a farlo con downloadhandler
, fileInput
e renderUI
, ma ho più di 200 di ingresso, sono sicuro che ci sia un modo semplice.
ogni idea sono i benvenuti, Grazie in anticipo
Dimitri
shiny::runApp(list(
ui = pageWithSidebar(
headerPanel("Save Input"),
sidebarPanel(
downloadButton("download.input","Download Input"),
## Bolean to read or not the old input of the file load bellow
checkboxInput("use.list.input","Use Rdata for input",F),
fileInput('file.Rdata','Reload the input of a last session')
),
mainPanel(
## All the input will become uiOUtput
uiOutput("num1"),
uiOutput("num2")
)
),
server = function(input,output){
## The downloadHandler to write the current input
output$download.input <- downloadHandler(
filename = function() { paste0("input", '.csv') },
content = function(name) {
write.table(save.input(), file=name)
}
)
### Two object, one for write the current input, one for read the old input
save.input<-reactive({
data<-cbind(c("number1","number2"),c(input$number1,input$number2))
return(data)
})
table.input<-reactive({
inFile<-input$file.Rdata
table.input<-read.table(inFile$datapath)
return(table.input)
})
### RenderUI ###
output$num1<-renderUI({
if(input$use.list.input==T){
default<-table.input()[1,2]
}else{default<-1}
numericInput("number1","number1",default)
})
output$num2<-renderUI({
if(input$use.list.input==T){
default<-table.input()[2,2]
}else{default<-2}
numericInput("number2","number2",default)
})
}
))