I'm building a web app that, among other things, would display Filing History data from Companies House API. This data can be pulled as follows:
library(httr)
library(jsonlite)
library(openssl)
library(dplyr)
### retrieving filing history ####
company_num = 'FC013908'
key = 'my_key'
fh_path = paste0('/company/', str_to_upper(company_num), "/filing- history")
fh_url <- modify_url("https://api.companieshouse.gov.uk/", path = fh_path)
fh_test <- GET(fh_url, authenticate(key, "")) #status_code = 200
fh_parsed <- jsonlite::fromJSON(content(fh_test, "text",encoding = "utf-8"), flatten = TRUE)
docs <- fh_parsed$items
> glimpse(docs)
Observations: 25
Variables: 20
$ type <chr> "AP01", "AP01", "CS01", "AA", "M...
$ action_date <chr> "2017-10-01", "2017-10-01", "201...
$ subcategory <chr> "appointments", "appointments", ...
$ category <chr> "officers", "officers", "confirm...
$ date <chr> "2017-11-22", "2017-11-22", "201...
$ description <chr> "appoint-person-director-company...
$ pages <int> 2, 2, 10, 36, 5, 38, 14, 1, 31, ...
$ barcode <chr> "X6JPZWQX", "X6JPZ6G8", "X6A72QU...
$ transaction_id <chr> "MzE5MDc4MTA5NGFkaXF6a2N4", "MzE...
$ paper_filed <lgl> NA, NA, NA, TRUE, NA, TRUE, NA, ...
$ associated_filings <list> [NULL, NULL, NULL, NULL, NULL, ...
$ description_values.officer_name <chr> "Mr Michael Anthony Norcott Thom...
$ description_values.appointment_date <chr> "2017-10-01", "2017-10-01", NA, ...
$ description_values.made_up_date <chr> NA, NA, "2017-07-07", "2017-04-0...
$ description_values.charge_number <chr> NA, NA, NA, NA, "SC1500750001", ...
$ description_values.charge_creation_date <chr> NA, NA, NA, NA, "2017-04-28", NA...
$ description_values.termination_date <chr> NA, NA, NA, NA, NA, NA, NA, "201...
$ description_values.description <chr> NA, NA, NA, NA, NA, NA, NA, NA, ...
$ links.self <chr> "/company/SC150075/filing-histor...
$ links.document_metadata <chr> "https://frontend-doc-api.compan...
Now, I want to create a hyperlink for all links.document_metadata
observations (or an action button next to each observation, doesn't matter) that would make another API call to fetch the actual document and open it in the browser, but only after it's been clicked on. All the necessary code to make such a call you can find here.
I'm not even sure how to approach this: If I wanted to create an actionButton
for every observation, how would I be able to observeEvent
for all of them? Alternatively, I could embed the link using
tagList("URL link:", url)
, as suggested here, but this way I would need to make API calls for every single item in the data.table, whether or not someone is going to click on it or not, and that would seriously slow the app down. Any ideas on how to go about it?