user0604
user0604

Reputation: 3

How to run another rscript using a button on another script in SHINY

How to run a code of an R script by clicking the actionButton in SHINY? The button would call the script saved in the same directory and run the script and i want to display the script name to be displayed in the URL.

Please help me out with this. Thanks in Advance!

Upvotes: 0

Views: 1899

Answers (1)

Gregor de Cillia
Gregor de Cillia

Reputation: 7685

@divibisan basically said it all in his comment. When you want to run a R script, you can use the command source as in

source("path/to/my/script.R")

All relative paths will be resolved based on your working directory (getwd()). If you have a shiny app and a script file (script.R) in the same directory, you can use

## file: app.R
shinyApp(
  fluidPage(
    actionButton("buttonId", "run script")
  ),
  function(input, output, session) {
    observeEvent(input$buttonId, {
      message("running script.R")
      source("script.R")
    })
  }
)

Then you run the app with

shiny::runApp("app.R")

or you just use the "run app" button in RStudio.

I dont't really get what you mean with "display the script name". You just include it in the ui?

Upvotes: 2

Related Questions