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
).
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.