Can you read the name/id of a piece of RStudio Connect content into an object in the session?

I have a shiny app, deployed into 2 different pieces of content as a method of doing an informal deployment pipeline. There is a test version, and the live version.

I am beginning to log user inputs to a database table to better understand how the app is being used. I'd like to gather as much info as possible to narrow down whether or not the app is being tested, or used live. For instance, I am logging the platform so I can tell if it's me testing the app locally ("windows").

I want to know if I'm in the test version or live version, which I can tell by the name, or the url, or the id, or whatever. If it's the test version, then I know it's me or one of the project stakeholders who are the only ones who know how to access it.

**Note - we primarily use RStudio Connect as anonymous users, I can't use the logged in named user as a way to help determine this.

Have you looked at the connectapi package? It provides some nice functionality that could help.

For example:

client <- connectapi::connect(
  server = Sys.getenv("CONNECT_SERVER"),
  api_key = Sys.getenv("CONNECT_API_KEY")
)

client |> 
  connectapi::get_usage_shiny() |>
  dplyr::glimpse()
Rows: 20
Columns: 5
$ content_guid <chr> "5a99fcf5-1294-41f0-b504-d9f7bce47abb", "e4376c1e-b8d6-48cb-b2e0-542b5d473…
$ user_guid    <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
$ started      <dttm> 2018-12-06 03:10:22, 2018-12-06 03:11:06, 2018-12-06 03:11:32, 2018-12-06…
$ ended        <dttm> 2018-12-06 03:10:45, 2018-12-06 03:11:29, 2018-12-06 03:11:55, 2018-12-06…
$ data_version <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1

Then, if you know the content guid if you dev and production content you can easily determine which app was being used.

Is this on the right track for what your are looking for?

Thanks for the suggestion. I think you have in mind that I use the api for getting the usage data? Not, specifically, to return the name of the content that is being run in the current session. I'm aware of the former use case with connectapi, but not the latter.

I think I misunderstood the original question. One approach could be to set an environment variable for each, say we name it CONTENT_ENVIRONMENT. For each app, give it a value like this:

Then, in your function that handles logging you can get this environment variable with Sys.getenv("CONTENT_ENVIRONMENT").

Genius!
Thanks.

(getting to 20 characters)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.