I have a shiny app that reads from 3 excel files: "file_1.xlsx","file_2.xlsx" and "file_3.xlsx". But it only reads when I choose the options on the selectInput widget.
The www
folder has a data
folder that I inlcude this 3 files.
The code to read theses folder is:
file_1 <- read_xlsx('www/data/file_1.xlsx')
file_2 <- read_xlsx('www/data/file_2.xlsx')
file_3 <- read_xlsx('www/data/file_3.xlsx')
file_1_new <- file_1 %>% mutate(new_column = 'time series')
file_2_new <- file_1 %>% mutate(new_column = 'time series')
file_3_new <- file_1 %>% mutate(new_column = 'time series')
And this is my app file:
library(shiny)
library(tidyverse)
file_1 <- read_xlsx('www/data/file_1.xlsx')
file_2 <- read_xlsx('www/data/file_2.xlsx')
file_3 <- read_xlsx('www/data/file_3.xlsx')
ui <- fluidPage(
selectInput(inputId = 'choices',label = "Files",choices = c('File1','File2','File3')),
plotOutput('chart')
)
server <- function(input, output, session) {
observeEvent(input$choices,{
if(input$choices == 'File1'){
output$chart <- renderPlot({ggplot(file_1, aes(x=x,y=y)) + geom_line(color = 'blue')})
}else{
if(input$choices == 'File2'){
output$chart <-renderPlot({ggplot(file_2, aes(x=x,y=y)) + geom_line(color = 'green')})
}else{
output$chart <-renderPlot({ggplot(file_3, aes(x=x,y=y)) + geom_line(color = 'red')})
}
}
}
)
}
shinyApp(ui, server)
In other words how can i make shiny reads the first file and then AFTER this run the app.