Applying an R code with Shiny

Hi,

I'm trying to use Shiny as a GUI for running an R code, so that people who don't usually use R will be able to operate. Essentially this script is just uploading two csv tables, choosing parameters (eg defining something like x=30, y=10) and letting the R script run normally. The output is just plots and two tables.
(note: I understand that in order for shiny to present the plots I need to use the appropriate commands in ui and server, but that is a more advanced thing I'd like to do in the future)

The code is already written in a "regular" R script. While running parts of it using "observe" and other reactivities, the global environment stays empty and it seems to me there's an easier way to perform this task than the way I'm trying to do it.

So, Is there an easy way to just let an R script run?
I've found this: runcode: Construct to let you run arbitrary R code live in a Shiny app in shinyjs: Easily Improve the User Experience of Your Shiny Apps in Seconds
but it says in the description that it is not recommended:

"... it should not be included in an app that is accessible to other people , as letting others run arbitrary R code can open you up to security attacks."

Best

Hi,

It's not that simple to just put a Shiny app on top of an R script as you'll have to build reactive environments over certain parts of the code.

If you like it really simple and don't mind the users having to start the script themselves (source button), you can use the svDialogs package for example to prompt input

library(svDialogs)

dlgMessage("Please select a CSV file")
inputFile = dlg_open(title = "Select one CSV file")$res
value=dlg_input(message = "Enter a value")$res

This way the user will get some input boxes when the script runs. It's up to you though to write code to check the validity of the input and prompt again if something goes wrong ...

Hope this helps,
PJ

1 Like

Thank you for you answer.

Best

Hi have a look at my code. Maybe it would be helpful. In case you think its may be useful i can creat a template for everyone out of it.

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.