r if(Sys.getenv('CONNECT_SERVER') == '') { "<h4>ERROR: You must set the CONNECT_SERVER environment variable</h4>\n" }
r if(Sys.getenv('CONNECT_API_KEY') == '') { "<h4>ERROR: You must set the CONNECT_API_KEY environment variable</h4>\n" }
r if(Sys.getenv('CONNECT_API_KEY') == '' || Sys.getenv('CONNECT_SERVER') == '') { knitr::knit_exit() }
library(connectapi) library(pins)
# library(httr) # # # Request a page of up to 25 users. # resp <- GET( # paste0(Sys.getenv("CONNECT_SERVER"), "__api__/v1/users?page_size=25"), # add_headers(Authorization = paste("Key", Sys.getenv("CONNECT_API_KEY"))) # ) # payload <- content(resp) # # payload_list <- list() # # While the current page has results, add its contents to the list holder # # then advance to the next page. # while(length(payload$result) > 0) { # # payload_list[[length(payload_list) + 1]] <- payload$results # # # get the next page # nextPage <- payload$current_page + 1 # resp <- GET( # paste0(Sys.getenv("CONNECT_SERVER"), "__api__/v1/users?page_size=25&page_number=", nextPage), # add_headers(Authorization = paste("Key", Sys.getenv("CONNECT_API_KEY"))) # ) # payload <- content(resp) # } # library(tidyr) # # # Unnest the list of lists into a single column tibble of lists # users_list <- unnest_longer(tibble::tibble(dat = payload_list), dat) # # # Rectangle the tibble of lists into a tibble of usable column data # df_users <- unnest_wider(users_list, dat)
Get user info using connectapi
conn <- connectapi::connect() df_users <- connectapi::get_users(src=conn, limit=Inf)
# Pin the user data in df_users to RStudio Connect board <- pins::board_rsconnect() board %>% pins::pin_write(df_users, name = "user-info", description = "Results pulled from the /v1/users API")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.