user12914910
user12914910

Reputation:

Issues when deploying Shiny app : Error in read.table

Although my app is working perfectly when I run it locally, I can't deploy it to shinyapps.io ! :(

Every single time I try, I get this annoying message:

Warning message: Error detecting locale: Error in read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'raw' (Using default: en_US)

My scripts and my csv file are saved under the right encoding (UTF-8) and I've added an empty line to my csv (but I still get the following warning "incomplete final line found by readTableHeader on 'raw'"

Here is my code and my csv file:

ui:

library(shiny)
library(leaflet)
library(dplyr)
library(magrittr)
library(devtools)
library(RColorBrewer)
library(rgdal)
library(raster)
library(sp)
library(shinydashboard)
library(tidyverse)
library(DT)
library(networkD3)
library(rsconnect)

communes <- readOGR("comm_etude_xl.shp")
tableau_excel <- read.csv("data_communes.csv", sep=";", encoding="UTF-8")

ui <- dashboardPage(
  dashboardHeader(title ="Projet impermeabilite"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Contexte", tabName = "intro", icon = icon("info")),
      menuItem("Carte", tabName = "map", icon = icon("map")),
      menuItem("Donnees brutes", tabName = "tableau", icon = icon("table"))
    )
  ),

  dashboardBody(
    tabItems(
      # First tab content
      tabItem(tabName = "map",
              fluidRow(
                valueBoxOutput("variable1"),#end box
                valueBoxOutput("variable2"),
                valueBoxOutput("variable3"),


                fluidRow(
                  box(height=450, status="primary", title="Carte", solidHeader=TRUE, collapsible=TRUE, leafletOutput(outputId = "mymap", height="380")),
                  box(height=450, status="warning", title="Graphique", solidHeader=TRUE, collapsible=TRUE, plotOutput(outputId = "myplot", height="380")
                  ))
              )),

      # Second tab content
      tabItem(tabName = "intro", h2("Contexte de l'etude")
      ),

      # Third tab content
      tabItem(tabName = "tableau",  h2("Tableau csv"), 
              fluidRow(
                DT::dataTableOutput("table")
              )
      ))
  ))

server:

server <- function(input, output){

  ## use reactive values to store the id from observing the shape click
  rv <- reactiveVal()

  output$mymap<-renderLeaflet(
    leaflet(communes) %>%
      addProviderTiles(providers$Stamen.TonerLite,
                       options = providerTileOptions(noWrap = TRUE)) %>%
      setView(1.45, 43.52, zoom = 12) %>%
      addTiles()  %>% 
      addPolygons(fillColor = "blue",
                  weight = 2,
                  opacity = 1,
                  color = "white",
                  dashArray = "3",
                  fillOpacity = 0.3,
                  highlight = highlightOptions(
                    weight = 5,
                    color = "#666",
                    dashArray = "",
                    fillOpacity = 0.7,
                    bringToFront = TRUE),
                  layerId = ~nm_cmmn)
  )

  observeEvent(input$mymap_shape_click, {
    rv(input$mymap_shape_click$id)
  })

  ## you can now 'output' your generated data however you want
  output$myplot <- renderPlot({
    if (is.null(rv())) return (NULL)
    tableau_excel %>%
      filter(nom_commune == rv()) %>%
      pivot_longer(cols = starts_with("Variable"), names_to = "Variable", values_to = "Value") %>%
      ggplot(aes(x = Variable, y = Value)) +
      geom_col() + ggtitle("Aide de prise a la decision dans la gestion des inondations") +
      xlab("SWI, TWI, densite de population") + ylab("Valeurs normalisees") + labs(fill="SWI, TWI, densite de population")
  })


  output$table<-DT::renderDataTable({
    datatable(tableau_excel,
              class = 'cell-border stripe',
              editable = TRUE,
              options = list(scrollX = T))
  })

  output$variable1 <-renderValueBox({
    valueBox(
      "17.6%", "Pourcentage total de surfaces artificialisees sur la zone d'etude", icon = icon("building"),
      color = "red"
    )
  })

  output$variable2 <-renderValueBox({
    valueBox(
      "2147", "Nombre de personnes vivant dans la zone d'aleas inondation ", icon = icon("street-view"),
      color = "green"
    )
  })

  output$variable3 <-renderValueBox({
    valueBox(
      "4", "Nombre d'arretes de catastrophes naturelles sur la zone d'etude depuis 1983 ", icon = icon("cloud-showers-heavy"),
      color = "blue"
    )
  })


}

deployApp()

csv + shapefile: https://drive.google.com/drive/folders/1wlSAwgz3TRATg2KoBEo9LVdkBmnFSKJ7

Many thanks in advance for your help !

EDIT:

> rsconnect::showLogs()
2020-03-02T12:45:44.844363+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.409910+00:00 shinyapps[1888035]: ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
2020-03-02T12:45:45.414479+00:00 shinyapps[1888035]: ✔ ggplot2 3.2.1     ✔ purrr   0.3.3
2020-03-02T12:45:45.414480+00:00 shinyapps[1888035]: ✔ tibble  2.1.3     ✔ stringr 1.4.0
2020-03-02T12:45:45.414481+00:00 shinyapps[1888035]: ✔ tidyr   1.0.0     ✔ forcats 0.4.0
2020-03-02T12:45:45.414482+00:00 shinyapps[1888035]: ✔ readr   1.3.1     
2020-03-02T12:45:45.554173+00:00 shinyapps[1888035]: ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
2020-03-02T12:45:45.554175+00:00 shinyapps[1888035]: ✖ tidyr::extract()   masks raster::extract(), magrittr::extract()
2020-03-02T12:45:45.571473+00:00 shinyapps[1888035]:     dataTableOutput, renderDataTable
2020-03-02T12:45:45.554176+00:00 shinyapps[1888035]: ✖ dplyr::filter()    masks stats::filter()
2020-03-02T12:45:45.571474+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.571107+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.571471+00:00 shinyapps[1888035]: The following objects are masked from ‘package:shiny’:
2020-03-02T12:45:45.613669+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.571472+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.613967+00:00 shinyapps[1888035]: The following object is masked from ‘package:leaflet’:
2020-03-02T12:45:45.554177+00:00 shinyapps[1888035]: ✖ dplyr::lag()       masks stats::lag()
2020-03-02T12:45:45.613306+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.613968+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.554178+00:00 shinyapps[1888035]: ✖ purrr::set_names() masks magrittr::set_names()
2020-03-02T12:45:45.613309+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.624899+00:00 shinyapps[1888035]: Attaching package: ‘rsconnect’
2020-03-02T12:45:45.634453+00:00 shinyapps[1888035]: OGR data source with driver: ESRI Shapefile 
2020-03-02T12:45:45.554177+00:00 shinyapps[1888035]: ✖ raster::select()   masks dplyr::select()
2020-03-02T12:45:45.613308+00:00 shinyapps[1888035]: Attaching package: ‘networkD3’
2020-03-02T12:45:45.624897+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.625531+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.571097+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.613667+00:00 shinyapps[1888035]: The following object is masked from ‘package:DT’:
2020-03-02T12:45:45.624899+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.634465+00:00 shinyapps[1888035]: Source: "/srv/connect/apps/rshiny/comm_etude_xl.shp", layer: "comm_etude_xl"
2020-03-02T12:45:45.571106+00:00 shinyapps[1888035]: Attaching package: ‘DT’
2020-03-02T12:45:45.613668+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.625225+00:00 shinyapps[1888035]: The following object is masked from ‘package:devtools’:
2020-03-02T12:45:45.634480+00:00 shinyapps[1888035]: with 11 features
2020-03-02T12:45:45.613669+00:00 shinyapps[1888035]:     JS
2020-03-02T12:45:45.625225+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.634487+00:00 shinyapps[1888035]: It has 6 fields
2020-03-02T12:45:45.625226+00:00 shinyapps[1888035]:     lint
2020-03-02T12:45:45.625226+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.613967+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.613968+00:00 shinyapps[1888035]:     JS
2020-03-02T12:45:45.625530+00:00 shinyapps[1888035]: 
2020-03-02T12:45:45.625530+00:00 shinyapps[1888035]: The following object is masked from ‘package:shiny’:
2020-03-02T12:45:45.625531+00:00 shinyapps[1888035]:     serverInfo
2020-03-02T12:45:48.398235+00:00 shinyapps[1888035]: Warning: Error in : You must register an account using setAccountInfo prior to proceeding.
2020-03-02T12:45:48.401925+00:00 shinyapps[1888035]:   67: stop
2020-03-02T12:45:48.401926+00:00 shinyapps[1888035]:   66: stopWithNoAccount
2020-03-02T12:45:48.401927+00:00 shinyapps[1888035]:   65: deploymentTarget
2020-03-02T12:45:48.401927+00:00 shinyapps[1888035]:   64: deployApp
2020-03-02T12:45:48.402019+00:00 shinyapps[1888035]: Error : You must register an account using setAccountInfo prior to proceeding.

EDIT 2:*

> rsconnect::showLogs()
2020-03-02T13:19:09.176637+00:00 shinyapps[1888035]: 
2020-03-02T13:19:09.176639+00:00 shinyapps[1888035]: 
2020-03-02T13:19:09.176967+00:00 shinyapps[1888035]: The following object is masked from ‘package:devtools’:
2020-03-02T13:19:09.176968+00:00 shinyapps[1888035]: 
2020-03-02T13:19:09.176969+00:00 shinyapps[1888035]:     lint
2020-03-02T13:19:09.186971+00:00 shinyapps[1888035]: OGR data source with driver: ESRI Shapefile 
2020-03-02T13:19:09.176969+00:00 shinyapps[1888035]: 
2020-03-02T13:19:09.177268+00:00 shinyapps[1888035]: The following object is masked from ‘package:shiny’:
2020-03-02T13:19:09.177269+00:00 shinyapps[1888035]: 
2020-03-02T13:19:09.177270+00:00 shinyapps[1888035]:     serverInfo
2020-03-02T13:19:09.177270+00:00 shinyapps[1888035]: 
2020-03-02T13:19:09.186988+00:00 shinyapps[1888035]: Source: "/srv/connect/apps/rshiny/comm_etude_xl.shp", layer: "comm_etude_xl"
2020-03-02T13:19:09.186989+00:00 shinyapps[1888035]: with 11 features
2020-03-02T13:19:09.187010+00:00 shinyapps[1888035]: It has 6 fields
2020-03-02T13:19:14.115280+00:00 shinyapps[1888035]: Warning: Error in structure: object 'communes' not found
2020-03-02T13:19:14.120848+00:00 shinyapps[1888035]:   114: structure
2020-03-02T13:19:14.120852+00:00 shinyapps[1888035]:     6: eval
2020-03-02T13:19:14.120849+00:00 shinyapps[1888035]:   111: leaflet
2020-03-02T13:19:14.120850+00:00 shinyapps[1888035]:   107: func
2020-03-02T13:19:14.120851+00:00 shinyapps[1888035]:    94: origRenderFunc
2020-03-02T13:19:14.120851+00:00 shinyapps[1888035]:    13: runApp
2020-03-02T13:19:14.120852+00:00 shinyapps[1888035]:    12: fn
2020-03-02T13:19:14.120851+00:00 shinyapps[1888035]:    93: output$mymap
2020-03-02T13:19:14.120852+00:00 shinyapps[1888035]:     7: connect$retry
2020-03-02T13:19:14.120852+00:00 shinyapps[1888035]:     5: eval
2020-03-02T13:20:56.884363+00:00 shinyapps[1888035]: Warning: Error in structure: object 'communes' not found
2020-03-02T13:20:56.887735+00:00 shinyapps[1888035]:   114: structure
2020-03-02T13:20:56.887737+00:00 shinyapps[1888035]:   111: leaflet
2020-03-02T13:20:56.887738+00:00 shinyapps[1888035]:    94: origRenderFunc
2020-03-02T13:20:56.887769+00:00 shinyapps[1888035]:     5: eval
2020-03-02T13:20:56.887738+00:00 shinyapps[1888035]:    93: output$mymap
2020-03-02T13:20:56.887739+00:00 shinyapps[1888035]:    12: fn
2020-03-02T13:20:56.887739+00:00 shinyapps[1888035]:     7: connect$retry
2020-03-02T13:20:56.887739+00:00 shinyapps[1888035]:     6: eval
2020-03-02T13:20:56.887737+00:00 shinyapps[1888035]:   107: func
2020-03-02T13:20:56.887738+00:00 shinyapps[1888035]:    13: runApp
2020-03-02T13:20:59.764571+00:00 shinyapps[1888035]:   116: crosstalk::is.SharedData
2020-03-02T13:20:59.764585+00:00 shinyapps[1888035]:     7: connect$retry
2020-03-02T13:20:59.764572+00:00 shinyapps[1888035]:   115: datatable
2020-03-02T13:20:59.764585+00:00 shinyapps[1888035]:     6: eval
2020-03-02T13:20:59.764574+00:00 shinyapps[1888035]:   112: func
2020-03-02T13:20:59.764573+00:00 shinyapps[1888035]:   114: exprFunc [/srv/connect/apps/rshiny/server.R#44]
2020-03-02T13:20:59.764586+00:00 shinyapps[1888035]:     5: eval
2020-03-02T13:20:59.764584+00:00 shinyapps[1888035]:    93: output$table
2020-03-02T13:20:59.764573+00:00 shinyapps[1888035]:   113: widgetFunc
2020-03-02T13:20:59.764574+00:00 shinyapps[1888035]:    99: origRenderFunc
2020-03-02T13:20:59.764584+00:00 shinyapps[1888035]:    94: origRenderFunc
2020-03-02T13:20:59.764584+00:00 shinyapps[1888035]:    98: renderFunc
2020-03-02T13:20:59.760900+00:00 shinyapps[1888035]: Warning: Error in crosstalk::is.SharedData: object 'tableau_excel' not found
2020-03-02T13:20:59.764585+00:00 shinyapps[1888035]:    13: runApp
2020-03-02T13:20:59.764585+00:00 shinyapps[1888035]:    12: fn

Upvotes: 1

Views: 861

Answers (1)

mhovd
mhovd

Reputation: 4087

You have trailing semicolons in your data and header.

nom_commune;code_insee;population;TWI;Variable_densite;Variable_SWI_moyen;Variable_TWI_moyen;
PORTET-SUR-GARONNE;31433;9836;13.776;2.77782654494382;5.7465495608532;10;;

Several of your lines ends with a semicolon, which might cause trouble with your import. Try removing these, and see if it helps.

Upvotes: 0

Related Questions