I upload a file to shiny (csv or excel) and I create an object with the file data. I want this object global because I use the data across different outputs.
My original (simplified) server.R code is:
shinyServer(function(input, output) { output$contents <- renderTable({ inFile <- input$file1 if (is.null(inFile)) return(NULL) data <- read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote, dec = ".") data }) output$grafic <- renderPlot({ inFile <- input$file1 if (is.null(inFile)) return(NULL) data <- read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote, dec = ".") barplot(table(data$SEVERIDAD), main="Severitat dels riscos detectats") }) }) So, I have to repeat the code in order to create the object "data" two times.
After read other posts I tried this code but doesn't work:
inFile <- input$file1 if (is.null(inFile)) return(NULL) data <- read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote, dec = ".") shinyServer(function(input, output) { data <- reactive(data) output$contents <- renderTable({ data <- data() data }) output$grafic <- renderPlot({ data <- data() barplot(table(data$SEVERIDAD), main="Severitat dels riscos detectats") }) }) I think that the last code doesn't work because no file can't be uploaded when the application is loaded.
Thanks!