FromJSON in Shiny App

Hi everyone,

I made a shiny application. In this application, my data comes from JSON query but it works in local but it does not work in shinyapps.io.

Please, please and please help me...

My query:

    ispark_refresh <-reactive({
      
fromJSON("https://api.ibb.gov.tr/ispark/Park",flatten = T)
      
      
    })

My Log:

It looks like the URL that you are trying to reach is not responding to requests from shinyapps.io. This could be for many reasons - either the request that is being made is in such a way that the API is not responding, or the API has some type of firewall rule set up that blocks requests, etc. I just tried this and things worked fine for me though (from local and from shinyapps.io)! I just used system("curl -i https://api.ibb.gov.tr/ispark/Park"). It might be worth doing some exploration rather than just using fromJSON. For instance:

  • httr::content(httr::GET("https://api.ibb.gov.tr/ispark/Park"), as = "text")
  • system("curl -i https://api.ibb.gov.tr/ispark/Park")

You could also throw these in the global part of the Shiny app startup (right around the library() commands and such) to ensure there is not something weird going on with reactivity!

It's also possible that something has changed in networking / security of this API since you submitted the request, which is why requests work for me now?

2 Likes

Dear Cole,

Thank you for your repsonse!!

How will I turn to dataframe this structure without fromjson function?

httr::content(httr::GET("https://api.ibb.gov.tr/ispark/Park"), as = "text")

Colnames must be: "ParkID", "Latitude","Longitude","Kapasitesi","BosKapasite","ParkTipi","Ilce","Distance","UcretsizParklanmaDk"

For the second code:

system("curl -i https://api.ibb.gov.tr/ispark/Park")

Screenshot of output:

Perfect!! It's working!! Is jsonlite::fromJSON() (I presume you are using jsonlite?) still failing?

If this works, but fromJSON still fails, you may want to submit a bug in the jsonlite package.

In the meantime, though - once you have the text value, you can then convert a few different ways:

# will give you a "parsed" list output
httr::content(httr::GET("https://api.ibb.gov.tr/ispark/Park"), as = "parsed")

# use `fromJSON` on the string itself
jsonlite::fromJSON(httr::content(httr::GET("https://api.ibb.gov.tr/ispark/Park"), as = "text"))

OMG!!! It is worked!!!!! Thank you Mr. Cole!!!!!!!! :upside_down_face: :upside_down_face: :upside_down_face:

1 Like

Woohoo!! Glad to hear! Well done! :smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.