Выгрузка CSV-файла на текстовый файлinyApps.io без подключения: какой каталог - PullRequest
0 голосов
/ 07 октября 2019

При попытке заставить работать Shiny App в shinyapps.io это не работает. После многочисленных попыток включить мой набор данных «округов» для чтения shinyapps.io, он продолжает выдавать следующую ошибку: не могу открыть файл ./counties.csv: такого файла или каталога нет + Предупреждение: ошибка в файле:не могу открыть соединение

Это код, который я использую для 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")))
)
)

И это код для сервера

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 

Если естьподсказка, как это исправить, пожалуйста, дайте мне знать.

Getwd () дает следующее: "C: / Users / Gebruiker / Documents / Earth Science Scriptie"

В этой папке всемои данные + скрипты сохранены.

1 Ответ

0 голосов
/ 09 октября 2019

Вот общее решение для просмотра файлов и чтения файла CSV.

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