How to get user_id in the website created by learnr and published in RStudio Connect.

Does anyone have the experience of getting the user_id in the website created by learnr and published in RStudio Connect? We are building a e-learning service for R language with learnr package and RStudio Connect.
For implementing individualized learning log and recommendation, we would like to get the log in ID (with RStudio Connect) of the current user and store all the learning process of this user. However, whatever the current user is, in the back-end build by learnr's "user_id" parameter (https://rstudio.github.io/learnr/publishing.html), we can only get "rstudio-connect" as the user ID. For example, the current user is lillianTest in rstudio connect, so we want to get the “lillianTest” to store in our database, but now it return the “rstudio-connect”.


firebase(1)

Is there any suggestion to get the current user ID with learnr package and RStudio Connect?
Many Thanks,

This is a fantastic question!! The way that this is usually determined is by the session$user(), which Connect sets (in Shiny applications). This is described here:

https://shiny.rstudio.com/articles/client-data.html

I haven't tried this in a learnr module yet, but hopefully I will either have time to do so or someone else can comment as to whether this is possible / what changes are necessary! Hopefully that direction is helpful to get started, at least!

EDIT: This is also described (in the context of Connect) here: https://docs.rstudio.com/connect/user/shiny.html#user-meta-data

2 Likes

This is a great question !

Already asked my self how to do that once. It was not so obvious how learnr and RStudio Connect work together.

@cole what you are proposing works very well for shiny apps. For learner tutorial, as pointed by @tsaitzu01, there is a special mechanism where learn uses, per the doc

Account name of server user executing the tutorial

@tsaitzu01 I think that is why you get rstudio-connect because by default, it is the user that executes the R process on RStudio Connect.
One easy way so solve this would be to change the user. It is possible if your admin configured this feature:

This would allow the identified user to run the tutorial in its name, and then it would be recorded by learnr. I did no follow this way because our RStudio Connect server does not support this feature yet.

@cole, I tried with shiny usage data but this does not seem to be the way learnr is working. So I did not manage to make it work.
Also, that is more a long shot but there is way to customise the learnr identifier:
https://rstudio.github.io/learnr/publishing.html#custom-identifiers

That would mean having the username pass through the header using rstudio connect. Currently I don't think this is the case. Maybe there is some configuration that feasible with Connect to use this feature.

Anyway, this is another thing I encountered on a long TODO I have. I could make a reproductible example also when I find time.

@cole, do you already have one ? Did you manage to make the Tutorial Identifier from learn works with RStudio Connect ? The only way I found wes User Account for Processes

2 Likes

I haven't had a chance to dig in super deep, and have not tested the Tutorial Identifier, but it is possible to get the user's name from a server process in learnr. I made a simple example below. Hopefully I can get more time to play with this later! If there is some piece of this missing, we can definitely put it in as a feature request to learnr! Is this context useful for the user's name / information? Or does this information need to be accessible elsewhere?

This is described in more detail here:

https://rstudio.github.io/learnr/#shiny_components

And you can see my username exposed in the learnr tutorial.

2 Likes

This information can be access for learnr tutorial indeed but can’t be pass to the event recorder from within the tutorial.

There is a customization mechanism but I am not sure it is yet integrated with rstudio connect but I m’y be wrong as it is not well documented

Tutorial hosting services will often need to customize these identifiers based on their own notions of tutorial provisioning and user identify.

The customization works by defining headers containing the information but not sure how to make this works with rstudio connect.

In my POV, there is a missing piece in learnr to take advantage of user identification in rstudio connect.

I’ll try to complete you example and open an issue in learnr repo.

1 Like

The solution you provided works! We can get the user id in the interactive tutorial page and in our database successfully. We truly appreciate all your help on this matter.

1 Like

After playing around the code, we found that the jsoneditOutput function is composed of loading and viewing the session data. In the final page, we would like to load the data into “session” but not showing the viewer? Any comments will be much appreciated.

Oh yes! I did that to show you what the values are / so you can explore interactively. You would just reference session$user in the server side and not pass it to a UI object. That way you can do whatever you want with the value (but not show it to the viewer).

I.e. just remove the jsoneditOutput object. That is just a nice way to display the values for interactive viewing. In actual use, you would definitely not show that information :smile:

1 Like

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