I am currently developing shiny applications that aim to teach R via interactive courses. For that purpose, I have already worked with multiple-choice questions and free-text questions. Now I want to tackle questions where the users of the app (students) can enter their own R code in a text field and run it.
My current implementation basically uses eval
inside an observer.
## evaluate the users expression and store the results.
observeEvent(input$evluate, {
reactives$result <- eval(parse(text = input$console_in))
})
This implementation has serious drawbacks when it comes to security since users can insert and run arbitrary codes on the server.
- What are the best practices to make the console safer?
- How should the working directory be specified during the evaluation?
It is planned to release an open-source version of this software at some point. Therefore, I would prefer a solution which is not platform dependent and which doesn't complicate the deployment of the application.