Reputation: 3
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
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