0

New to Rstudio and I am trying to connect to the Rstudio connect to get statisitcs of all apps in the last 60 days. However. I do not receive the statistics and receive the below errors

rsc_server <- "https://rstudio.hartxxx.com/"
Sys.setenv("RSTUDIO_CONNECT_API_KEY" = rstudioapi::askForPassword("Enter Connect Token:Uxxx"))

library(httr)

rsc_get <- function(endpoint_call){
  rsc_call <- paste0(rsc_server, "__api__/v1/", endpoint_call)
  rsc_auth <- add_headers(Authorization = paste("Key", Sys.getenv("RSTUDIO_CONNECT_API_KEY")))
  resp <- GET(rsc_call, rsc_auth)
  content(resp)
}  

rsc_users <- rsc_get("users")  
names(rsc_users)
rsc_users$total
names(rsc_users$results[[1]])
five_days <- paste0(Sys.Date() - 60, "T00:00:00-00:00")
rsc_shiny <- rsc_get(paste0("instrumentation/shiny/usage?from=", five_days))

names(rsc_shiny$results[[1]])
library(purrr)
library(tibble)
shiny_usage <- map_dfr(
  rsc_shiny$results,
  ~ tibble(
    guid = .x$content_guid,
    user = ifelse(is.null(.x$user_guid), "anonymous", .x$user_guid),
    started = .x$started,
    ended = .x$ended,
    ver = .x$data_version
  )
)
glimpse(shiny_usage)

Observations: 12
Variables: 6
$ content_guid     <chr> "a261edd3-fa51-4878-8afc-b7fe662a6c37", "a261edd3-fa51-4878...
$ user_guid        <chr> NA, NA, NA, NA, "e96068bd-5e9f-4a5a-ab87-483f084f13fa", NA,...
$ started          <dttm> 2021-08-18 14:36:33, 2021-08-18 15:04:21, 2021-08-18 15:44...
$ ended            <dttm> 2021-08-18 15:00:46, 2021-08-18 16:37:51, 2021-08-18 17:11...
$ data_version     <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
$ session_duration <drtn> 24.21667 mins, 93.50000 mins, 87.56667 mins, 72.46667 mins..
NewInPython
  • 247
  • 1
  • 5
  • 13
  • `library(purrr); library(tibble);` should solve both of those. Or use `purrr::map_dfr` and `tibble::glimpse`. – r2evans Aug 24 '21 at 16:24
  • 1
    BTW, you should also be getting parsing errors from this script: `60_days` is not a legal R variable name. While you *can* create a variable with that name, you must force it using backticks, such as `\`60_days\` <- paste0(Sys.Date() - 60, "T00:00:00-00:00")`. – r2evans Aug 24 '21 at 16:26
  • @r2evans thanks for your responses. The link pasted for the question is already answered here does not answer my question unfortunately, so im curious as a new user why my question is closed – NewInPython Aug 24 '21 at 16:28
  • 1
    The error is literally `could not find function`. Your code does not include `library(purrr)`. (And your code has at least one parsing error in it.) I don't know how it could be anything else, can you add `library(purrr)` and rerun your script and then update your question, please? – r2evans Aug 24 '21 at 16:30
  • @r2evans i have edited the question. receiving the same error – NewInPython Aug 24 '21 at 16:36
  • 1
    What’s the output when you run library(purrr), do you get an error? If that works, then you could not be getting the “could not find function” error. Please post the output of sessionInfo() at the time you get the error. Is this the exact version of the script you are running? – MrFlick Aug 24 '21 at 16:41
  • Yes this is the exact version. i have only changed server name and api. Now i am getting some output but it is not usage statistics. – NewInPython Aug 24 '21 at 16:51
  • 1
    I'm still curious what `sessionInfo()` will show; it might show version-specific issues. – r2evans Aug 24 '21 at 17:23
  • can we please continue this on a discussion board. I can paste the output of sessionInfo there if u like – NewInPython Aug 24 '21 at 17:24
  • 1
    Well, now the original error is gone. This is basically a completely different question now since you are no longer getting errors. You seem to be getting output, how is that not exactly what you wanted? What values were you expecting? – MrFlick Aug 24 '21 at 17:45
  • 1
    From https://stackoverflow.com/q/68911836/3358272, I'm assuming that this question is resolved. Glad you've made progress! – r2evans Aug 24 '21 at 17:47
  • I am expecting to understand how many times the app is used not the average time it has been used. Thanks @r2evans – NewInPython Aug 24 '21 at 17:49

0 Answers0