Anass El Ghellab Anass El Ghellab - 1 year ago 99
JSON Question

Display HTTP GET Data in SHINY

I have a PostgreSQL database for which I created RESTful Api's using Talend DI that allow me to query tables

Now my question is how to call my Api's in Shiny and display the data received ?

example of http get response :

[{"medical_consultations":{"medical_consultation":[{"id":"1640087","id_consultation":"GFAPAAPA P 834406012009","consultation_date":"07-01-2009","id_center":"APA"},{"id":"1640088","id_consultation":"GFAPAAPA P1079007012010","consultation_date":"08-01-2010","id_center":"APA"},{"id":"1640089","id_consultation":"GFAPAAPA P1098811052007","consultation_date":"12-05-2007","id_center":"APA"}]}}]

Ps: I have no problem doing it using 'RPostgreSQL' package in Shiny to connect directly to my database but I prefer to separate it from shiny and that would be by using my web services

Answer Source

If you have the API all setup then you could do something like this:


url <- ""

ui <- fluidPage(
      textInput('GETargs',"GET string"),

server <- function(input, output, session) {
  observeEvent(input$sendGET, {
    getargs <- input$GETargs

    if( is.null(input$GETargs) ) getargs <- ""

    res                <- GET(sprintf("%s%s",url, getargs))
    output$GETresponse <- renderPrint(content(res))

    output$table1 <- renderDataTable($args) )


For example setting the text in the textbox to "param1=value1&param2=value2" sends a GET request to the selected URL. This might not be the way you want to implement this but maybe this gives you some idea on how this can be done.

If i use the example query sting I could for instance access "param1"'s value by typing: