Unnest list response in Shiny

Hi all,

I'm a bit stuck with a shiny app I'm producing in shiny with flexdashboard, it should display downloads per month for certain items. I'm accessing an API and the output it generates is a list of lists. In plain text it looks like:

{"timeline": {"2020-02": 6, "2020-03": 16, "2019-12": 17, "2019-06": 5, "2019-07": 7, "2019-04": 6, "2019-05": 5, "2020-04": 25, "2019-08": 1, "2019-09": 0, "2020-01": 10, "2020-05": 7, "2019-11": 13, "2019-10": 0}}

I want to remove the 'timeline' level but haven't had any success with what I've tried so far. I was able to remove it using substring but when I rendered the table it looked exactly the same as below:

The code I'm using is as follows:

timeline_dl_month_author_call <- reactive({> glue(BASE ADDRESS,input$timelinedlauthor)})
timeline_dl_month_author_data <- reactive({GET(timeline_dl_month_author_call(), authenticate(USERNAME,PASSWORD, type = 'basic'))})
timeline_dl_month_author_text <- reactive({content(timeline_dl_month_author_data(), "text")})
renderText(timeline_dl_month_author_text())
timeline_dl_month_author_df <- reactive({as.data.frame.matrix(timeline_dl_month_author_text)})
renderTable(timeline_dl_month_author_df())

I'm a self-taught novice so may be doing something very obviously wrong. I think my main issue is with the output format that the API sends this info in but there's not much I can do to change that so I'd really appreciate any suggestions.

your object is a json.

myobj <- '{"timeline": {"2020-02": 6, "2020-03": 16, "2019-12": 17, "2019-06": 5, "2019-07": 7, "2019-04": 6, "2019-05": 5, "2020-04": 25, "2019-08": 1, "2019-09": 0, "2020-01": 10, "2020-05": 7, "2019-11": 13, "2019-10": 0}}'

library(jsonlite)
library(tidyverse)

(myobj2 <- jsonlite::fromJSON(myobj))

(myobj3 <- myobj2$timeline)

(myobj4 <- as_tibble(myobj3))

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