Ubuntu 18.04: Error in rgdal::ogrListLayers(input) : Cannot open data source

I'm trying to follow the Leaflet tutorial for chloropeth maps but just getting an error in the first lines as I cannot read the geojson data.

*tried making a reprex but couldn't as reported here: reprex no input provided

library(leaflet)
library(geojsonio)
library(rgdal) #loaded this because I was having troubles reading the geojson data


# From http://leafletjs.com/examples/choropleth/us-states.js
states <- geojsonio::geojson_read("json/us-states.geojson", what = "sp")

Error:

Error in rgdal::ogrListLayers(input) : Cannot open data source

I've copied and save the contents of http://leafletjs.com/examples/choropleth/us-states.js and saved it in a text file with extention .geojson on a json folder inside my projects directory.

This is the URL for the tutorial:

https://rstudio.github.io/leaflet/choropleths.html

When in terminal I do:

sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev

System tells me everything is installed and need no updates.

What else should I do?

sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev

ogonzales@ogonzales:~$ sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
Leyendo lista de paquetes... Hecho
Creando árbol de dependencias
Leyendo la información de estado... Hecho
libgdal-dev ya está en su versión más reciente (2.2.3+dfsg-2).
libgeos-dev ya está en su versión más reciente (3.6.2-1build2).
libproj-dev ya está en su versión más reciente (4.9.3-2).
libudunits2-dev ya está en su versión más reciente (2.2.26-1).
Los paquetes indicados a continuación se instalaron de forma automática y ya no son necesarios.
linux-headers-4.15.0-23 linux-headers-4.15.0-23-generic
linux-image-4.15.0-23-generic linux-modules-4.15.0-23-generic
linux-modules-extra-4.15.0-23-generic
Utilice «sudo apt autoremove» para eliminarlos.
0 actualizados, 0 nuevos se instalarán, 0 para eliminar y 198 no actualizados.

Sys.Info:


Session info --------------------------------------------------------
setting value
version R version 3.4.3 (2017-11-30)
system x86_64, linux-gnu
ui RStudio (1.1.383)
language es_ES:en_US:en
collate es_ES.UTF-8
tz America/Lima
date 2018-08-11

Packages ------------------------------------------------------------
package * version date
base * 3.4.3 2017-12-01
class 7.3-14 2015-08-30
classInt 0.2-3 2018-04-16
compiler 3.4.3 2017-12-01
crosstalk 1.0.0 2016-12-21
curl 3.2 2018-03-28
datasets * 3.4.3 2017-12-01
DBI 1.0.0 2018-05-02
devtools 1.13.6 2018-06-27
digest 0.6.15 2018-01-28
e1071 1.6-8 2017-02-02
foreign 0.8-69 2017-06-21
geojson 0.2.0 2017-11-08
geojsonio * 0.6.0.9100 2018-08-11
graphics * 3.4.3 2017-12-01
grDevices * 3.4.3 2017-12-01
grid 3.4.3 2017-12-01
htmltools 0.3.6 2017-04-28
htmlwidgets 1.2 2018-04-19
httpuv 1.4.3 2018-05-10
httr 1.3.1 2017-08-20
jqr 1.0.0 2017-09-28
jsonlite 1.5 2017-06-01
later 0.7.2 2018-05-01
lattice 0.20-35 2017-03-25
lazyeval 0.2.1 2017-10-29
leaflet * 2.0.0 2018-04-20
magrittr 1.5 2014-11-22
maptools 0.9-3 2018-07-31
memoise 1.1.0 2017-04-21
methods * 3.4.3 2017-12-01
mime 0.5 2016-07-07
promises 1.0.1 2018-04-13
R6 2.2.2 2017-06-17
Rcpp 0.12.18 2018-07-23
rgdal * 1.3-4 2018-08-03
rgeos 0.3-28 2018-06-08
sf 0.6-3 2018-05-17
shiny 1.1.0 2018-05-17
sp * 1.3-1 2018-06-05
spData 0.2.8.3 2018-03-25
stats * 3.4.3 2017-12-01
tools 3.4.3 2017-12-01
units 0.6-0 2018-06-09
utils * 3.4.3 2017-12-01
V8 1.5 2017-04-25
withr 2.1.2 2018-08-11
xtable 1.8-2 2016-02-05
yaml 2.2.0 2018-07-25
source
local
CRAN (R 3.4.0)
CRAN (R 3.4.3)
local
CRAN (R 3.4.3)
CRAN (R 3.4.3)
local
CRAN (R 3.4.3)
CRAN (R 3.4.3)
cran (@0.6.15)
cran (@1.6-8)
CRAN (R 3.4.0)
CRAN (R 3.4.3)
Github (30b0969)
local
local
local
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.0)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
local
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
cran (@0.12.18)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
CRAN (R 3.4.3)
cran (@1.3-1)
CRAN (R 3.4.3)
local
local
CRAN (R 3.4.3)
local
CRAN (R 3.4.3)
Github (r-lib/withr@fe56f20)
CRAN (R 3.4.3)
cran (@2.2.0)

It resulted that the package was well installed.

But the tutorial was not clear enough for people with title to none javascript knowledge.

From the data provided in tutorial, I had to delete the var:

var statesData = and the trailing semicolon.

After that It loads and I can plot the leaflet map.

Thanks to geojson r package developer for the fix.