4

I am trying to make shiny app that takes data from this api: https://www.riigiteenused.ee/api/et/all. I need to use jsonlite::fromJSON, because it has good flatten function. When I use the following code (minimal example, in real life I do more stuff with data):

library(jsonlite)
data=fromJSON("https://www.riigiteenused.ee/api/et/all")

server <- function(input, output) {
  output$tekst <- renderText({
  nchar(data)
   })
 }

ui <- fluidPage(
  sidebarLayout(
   sidebarPanel(),
    mainPanel(textOutput("tekst"))
 ))

shinyApp(ui = ui, server = server)

I get following error message:

Error in open.connection(con, "rb") : 
Peer certificate cannot be authenticated with given CA certificates

I tried the following (go around ssl verify peer):

library(RCurl)
raw <- getURL("https://www.riigiteenused.ee/api/et/all", 
.opts = list(ssl.verifypeer = FALSE), crlf = TRUE)
data=fromJSON(raw)

It reads in raw data, but messes up JSON (validate(raw) shows lexical error: invalid character \n inside string, which is causing following error):

Error: lexical error: invalid character inside string.
      ressile: laevaregister@vta.ee.  Avaldusele soovitatavalt lis
                 (right here) ------^

Also one idea I tried was:

data=fromJSON(readLines("https://www.riigiteenused.ee/api/et/all"))

It works fine in my computer, but when I upload it to shinyapps.io app doesn't work and from logs I see error:

Error in file(con, "r") : https:// URLs are not supported

Could somebody give me a clue, if there is a way to load JSON data from https toshiny app using jsonlite fromJSON function?

My session info is following:

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Estonian_Estonia.1257  LC_CTYPE=Estonian_Estonia.1257   
[3] LC_MONETARY=Estonian_Estonia.1257 LC_NUMERIC=C                     
[5] LC_TIME=Estonian_Estonia.1257    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] jsonlite_0.9.19 httr_1.0.0      RCurl_1.95-4.7 bitops_1.0-6          shiny_0.12.2   

loaded via a namespace (and not attached):
[1] Rcpp_0.12.2       digest_0.6.8      mime_0.4          R6_2.1.1         
[5] xtable_1.7-4      magrittr_1.5      stringi_1.0-1     curl_0.9.4       
[9] tools_3.2.2       stringr_1.0.0     httpuv_1.3.3      rsconnect_0.4.1.4
[13] htmltools_0.2.6  
Risto Hinno
  • 51
  • 2
  • 5

2 Answers2

1

don't skip ssl, try

fromJSON(content(GET("https://www.riigiteenused.ee/api/et/all"), "text"))
sckott
  • 5,755
  • 2
  • 26
  • 42
  • Still gave me same error: Error in curl::curl_fetch_memory(url, handle = handle) : Peer certificate cannot be authenticated with given CA certificates – Risto Hinno Dec 07 '15 at 08:35
  • Hmm, I don't know how to help. That call works for me. Wonder if there's a bad interaction being done from within the shiny app – sckott Dec 07 '15 at 14:22
0

I tried this solution that worked fine in my computer and in shiny server:

  library(rjson)
  library(jsonlite)
  fromJSON(url, flatten=T)
Risto Hinno
  • 51
  • 2
  • 5