简体   繁体   English

如何使用SHINY中另一个脚本上的按钮运行另一个rscript

[英]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? 如何通过单击SHINY中的actionButton运行R脚本的代码? 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. 该按钮将调用保存在同一目录中的脚本并运行该脚本,我想显示要在URL中显示的脚本名称。

Please help me out with this. 这个你能帮我吗。 Thanks in Advance! 提前致谢!

@divibisan basically said it all in his comment. @divibisan基本上在他的评论中说了这一切。 When you want to run a R script, you can use the command source as in 当您想运行R脚本时,可以像下面那样使用命令源

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

All relative paths will be resolved based on your working directory ( getwd() ). 所有相对路径都将根据您的工作目录( getwd() )进行解析。 If you have a shiny app and a script file ( script.R ) in the same directory, you can use 如果您在同一目录中有闪亮的应用程序和脚本文件( script.R ),则可以使用

## 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. 或者您只使用RStudio中的“运行应用”按钮。

I dont't really get what you mean with "display the script name". 我没有真正理解“显示脚本名称”的含义。 You just include it in the ui? 您只是将其包含在ui中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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