0
votes

When trying to get working Shiny App into shinyapps.io it does not work. After trying numerous ways how to include my "counties" dataset to be read by the shinyapps.io it keeps giving the following error: cannot open file './counties.csv': No such file or directory + Warning: Error in file: cannot open the connection

This is th code I use for ui.R

library(shiny)
library(ggplot2)
library(ggiraph)
library(readr)

counties <- read.csv("./counties.csv")

shinyUI(fluidPage(

  # Application title
  titlePanel("Spatial Distribution of Protest Events in Iran during 2005 - 2017"),

  sidebarPanel(
    selectInput(
      inputId = "counties",
      label   = "Protest Event Issue",
      choices = list("freq_prov_tot", "freq_prov_bio", "freq_prov_air", "freq_prov_def","freq_prov_wast", "freq_prov_green", "freq_prov_wat", "freq_prov_ind", "freq_prov_gen", "freq_prov_eff",
                     "freq_prov_plas", "freq_prov_cult", "freq_prov_cult", "freq_prov_flo", "freq_prov_haze", "freq_prov_clean", "freq_prov_add", "freq_prov_nat", "freq_prov_soil", "freq_prov_trees", "freq_prov_veh"), selected = "freq_prov_bio"
    )
  ), 
  fluidRow(column(12,
                  ggiraph::ggiraphOutput("county_map")))
)
)

And this is the code for the server

library(shiny)
library(ggplot2)
library(ggiraph)
library(readr)


shinyServer(function(input, output) {


  data2 <- observeEvent(input$counties, { 
    if (input$counties == "freq_prov_bio"){
      output$county_map<- renderggiraph({
        p<- ggplot(counties, aes(x=long, y=lat, group = group, fill = freq_prov_bio)) +
          xlab("Longitude") + ylab("Lattitude") + labs(fill = "Number of Protest Events\n regarding Biodiversity") + scale_fill_gradientn(colours = c(low = "grey", high = "black"), breaks=c(0,5,10,15), labels=c(0,5,10,15), limits=c(0,20)) +
          coord_map("polyconic" ) +
          geom_polygon_interactive(aes(tooltip = labs_bio))
        ggiraph(code = print(p)) })}
etcetera 

If there is any clue on how to fix this, please do let me know.

Getwd() gives the following: "C:/Users/Gebruiker/Documents/Earth Science Scriptie"

In this folder all my data + scripts are saved.

1
try saving the csv in a folder called Data (or something) in the working directory, then use counties <- read.csv("Data/counties.csv")nogbad
I did that also, but then it also gives the same error: cannot open file 'data/counties.csv': No such file or directory + Warning: Error in file: cannot open the connection I'm 100% sure the file is there though.SofieCroonenberg
Does the app work locally? There might be something useful on this page support.rstudio.com/hc/en-us/articles/…nogbad
Yes the code works fine locally. When I set the working directory as follows: setwd("C:/Users/Gebruiker/Documents/Earth Science Scriptie") I get the following error: Error in setwd: cannot change working directorySofieCroonenberg
I also added a folder called data to the shiny map, but this also does not work.SofieCroonenberg

1 Answers

0
votes

Here's a general solution to browse files and read a csv file.

# Upload csv file
library(shiny)
# Define UI
ui <- pageWithSidebar(
  # App title ----
  headerPanel("Upload and Print First Several Lines of a csv File"),
  # Sidebar panel for inputs ----
  sidebarPanel(
    label="Data Source",fileInput("fileName", "File Name")),

  # Main panel for displaying outputs ----
  mainPanel(
    textOutput(outputId = "text"))
)

# Define server logic
server <- function(input, output) {

    readcsvFile <- reactive ({
        if (is.null(input$fileName)) return(NULL)
        inFile <- input$fileName
        inData <- read.csv(inFile$datapath)
        return (inData)
    })

    output$text <- renderPrint ({
        inData <- readcsvFile()
        head(inData)
    })
}

shinyApp(ui, server)