Shinyapps can't find the excel file

I am working with COVID data from mi country and I want to use shinyapps to publish an interactive ggplot that shows the positive number of cases in Peru's Regions.

So I worked in a shiny web app script (single file). When I run the app and publish it I got in chrome the next message:

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

filter, lag

The following objects are masked from ‘package:base’:

intersect, setdiff, setequal, union

Error in value[3L] :
path does not exist: ‘C:/Users/Para llevar/OneDrive/Favorites/Tito/07. Impulso Pais/05. COVID-19/COVID_webapp/Expansion covid sistematizado.xlsx’
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted

I don't know what is happening. The excel file is in the same folder of the script and the workspace.

It seems like you are using an absolute path (or something that gets evaluated to one, like ~\) for the file, when working with shiny apps you have to use relative paths only.
Once the app is deployed to the server it doesn't has access to your local files anymore.

How can I fix the problem then?

Use a file path relative to your root project-folder. If you need more specific help, try to provide a reproducible example, please have a look at this resources, to learn how to create one for a shiny app

You are right. So I create another topic with all the data step by step of my case. Thank you for the advice and I left the new case here -> Updated case

I am currenty working with COVID data from mi country. This data is saved in my personal OneDrive's file excel. So I am aiming to build a shinyapp in which my peers can consult the development of positive cases of COVID in all Peru's Regions.

My df has 26 variables but only as a matter of example I am only using 4 variables and 3 days of data:

> evolucion_covid

     Fecha    Lima     La Libertad  Madre de Dios
1 2020-04-24   10           2             1
2 2020-04-25   15           4             3
3 2020-04-26   20           8             3

In order to get this data I used this code:

library(dplyr)
library(readxl)
library(ggplot2)
library(shiny)

evolucion_covid <- read_excel("C:/Users/Para llevar/OneDrive/Favorites/Tito/
07. Impulso Pais/05. COVID-19/COVID_webapp/Expansion covid sistematizado.xlsx", 
col_names = FALSE) ##  data's source

evolucion_covid[] <- lapply(evolucion_covid, function(x) if(is.factor(x)) 
                            as.numeric(levels(x))[x] else x)
evolucion_covid$Fecha <- as.Date(evolucion_covid$Fecha, origin = "1899-12-30")

Also I store the names of the Regions for the plot:

nombre_regiones <- c("Lima", "La Libertad", "Madre de Dios")

So with all set I started my app.R. I wanted to present both date input and a list of Regions to generate a plot in which we can see the positive cases until an specific date.

UI:

ui <- fluidPage(
  titlePanel("Evolución COVID-19"),
  sidebarLayout(
    mainPanel(
      plotOutput("trend")
    ),
    sidebarPanel(
      dateInput("Fecha", "Selecciona la fecha",
                min = "2020-03-01",
                max = "2020-06-30",
                format = "dd/mm/yyyy", 
                value = Sys.time()),
      selectInput("Regiones", "Selecciona Region", ## vector I generated earlier
                  choices = nombre_regiones,
                  selected = "Lima"),
      actionButton("act", "Consultar")
    )
  )
)

Server:

server <- function(input, output){
  
  observeEvent(input$act,{
    evolucion_covid_filt <- evolucion_covid %>% filter(Fecha <= input$Fecha )
    output$trend <- renderPlot({
      ggplot(evolucion_covid_filt, 
             aes(x = Fecha, y = !! rlang::sym(input$Regiones))) + 
             geom_line(na.rm = TRUE, color = "steelblue") + 
             geom_point(na.rm = TRUE, color = "steelblue") + 
             scale_x_date(date_labels = "%d, %m", date_breaks  ="7 day") + 
             theme(text = element_text(size = 20), 
                   axis.text.x = element_text(angle = 0, hjust = 1, size = 15), 
                   axis.text.y = element_text(size = 15))
    })
  })
}

shinyApp(ui = ui, server = server)

So I ran the app, it works perfectly locally and when I try to publish it this happens (I prior create my account in shinyapps and conected it with rsconnect::setAccountInfo).

Consult

And prior to publish it I got the next issue:

Line 6 Paths should be to files within the project directory.

The line 6 is where I import the excel file. I left a picture of the folder:

If I continue with the publish process the app is uplouded but I got the next message in the browser:

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Error in value[[3L]](cond) : 
  `path` does not exist: ‘C:/Users/Para llevar/OneDrive/Favorites/Tito/07. Impulso Pais/05. COVID-19/COVID_webapp/Expansion covid sistematizado.xlsx’
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

From this point I don't if the problem is the directory of the excel file or there is another complication I am not seeing.

evolucion_covid <- read_excel("Expansion covid sistematizado.xlsx", col_names = FALSE)

In order to do what you suggest I add this to my code at the begining:

setwd("C:/Users/Para llevar/OneDrive/Favorites/Tito/07. Impulso Pais/05. COVID-19/COVID_webapp/")

I do this because the files I am working on are not in my default working directory. So it works locally but I got this when I publish:

 Error in value[[3L]](cond) : 
  ERROR: cannot change working directory
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

I was searching how to fix it and don't know if I got to transfer the entire folder to my default working directory or there is another solution. Thanks in advance.

In order to solve it: Tools < Global Options < General and change the default working directory fix the problem. Next I applied the suggestion of @nirgrahamuk and it managed to publish it. Thanks.

Just to clarify, the preferred workflow would be to create a "Project" to develop your app, that way you wouldn't need to manually set your working directory (it gets automatically set to your project directory and doesn't affect the defaults).

1 Like

Thanks. I will also do that in the future.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.