简体   繁体   中英

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!

@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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM