Sandboxing R code snippets on Web for noob users

Hi all,

Does anybody have experience with creating sandboxes for users/readers of an online publication – in this case for R code?

What I want seems to be in between JupyterHub with an R-kernel and Shiny. But my audience is far from first rate programmers, so Jupyter is kind of giving them a tank where they need a squirt gun. Shiny looks like a way to create a nice and (indeed) shiny user experience, which would cover about 90% of what I need. But I would want the user also to be able to meddle around with a tiny piece of code and see the output within the site (much like JSFiddle).

I know, I know… security alert, hacking red flags, I know. But if I wanted that, what are my options?

Cheers
–Joris

Hi!

have you tried Swirl-based tutorials? It will still need a dedicated installation of RStudio, but could be a great way to learn.

UPD. Uh, not sure about the web & swirl actually.

1 Like

@joris.van.zundert have you tried using R in a Google Colab notebook? You can share a read-only notebook, which users can then copy into their Google Drive, run, and edit. To integrate with an article or online publication, you could include the snippets using R markdown or something static, and then below each block there could be “try this in Colab” type of thing. I have found Google Colab to be a nice way to get folks used to using a Jupyter Notebook. One caveat is that loading a big dataset can be cumbersome, but I found what I think is a good workaround if that’s a factor. Happy to share what I’ve done. Another caveat is you have to have a Google account. If that’s a dealbreaker, mybinder.org has directions for running an R kernel, but mybinder tends to be slower than colab. Check out https://github.com/binder-examples/r

1 Like

Thx, those are useful hints. Will investigate!

Shiny can easily do what you describe; could create a text box with the code (as the default value), accompanied with a button, that, when clicked, will pass the contents of the text box to some function that parse+evaluate it as R code (e.g. eval(parse(text="5+5")) ), and display the result in a mock console (see verbatimTextOutput() ). So they can edit the code and run it. Or alternatively, if it’s only about changing parameters not the actual code, could have some buttons and sliders for the params, which then generates a code example (just using values from the sliders using some combination of if-else and paste) in a nearby text box, so they’ll see how the code changes if they switch the options/params.

I need to learn more about shiny, but I believe glitch.com supports deploying containerized shiny apps.