【问题标题】:runapp shiny from other shiny application with actionbutton使用 actionbutton 从其他闪亮的应用程序运行闪亮的应用程序
【发布时间】:2016-02-09 03:13:31
【问题描述】:

当我在一个非常简单的闪亮应用程序中按下操作按钮时,我试图调用另一个闪亮的应用程序。另一个应用程序位于一个名为好处的文件夹中,其中包含 ui.R 和 server.R 文件,但是当我单击按钮时没有任何反应。我想做什么有可能吗??

干杯。

ui.R

library(shiny)

shinyUI(fluidPage(

  # Application title
  titlePanel("RunnApp"),
    mainPanel(
      actionButton("goButton", "Go!")
    )

))

服务器.R

library(shiny)

shinyServer(function(input, output) {
    ntext <- eventReactive(input$goButton, {
      runApp("benefits")
  })
            })

【问题讨论】:

  • 这是在服务器上,还是在您的本地机器上?

标签: r shiny


【解决方案1】:

临时答案:

我已经开始寻找这个问题的答案。本答案会及时更新。

#server.R



library(shiny)

shinyServer(function(input, output) {
  ntext <- eventReactive(input$goButton, {
    stopApp(runApp('C:/Users/Infinite Flash/Desktop/Dashboard'))
  })

  output$nText <- renderText({
    ntext()
  })
})



#ui.R

library(shiny)

shinyUI(pageWithSidebar(
  headerPanel("actionButton test"),
  sidebarPanel(
    actionButton("goButton", "Go!"),
    p("Click the button to update the value displayed in the main panel.")
  ),
  mainPanel(
    textOutput("nText")
  )
))

这段代码的好处在于它初始化了我用stop(runApp('C:/Users/Infinite Flash/Desktop/Dashboard')) 语句指定的应用程序。我可以验证它确实运行了该应用程序,因为我在该应用程序中有一个 global.R 文件,该文件具有 6 个预加载的数据集,该应用程序在启动之前需要加载这些数据集。我知道它运行了,因为在这行代码运行之后,我的环境中有这些对象(由引用的应用程序中的 global.R 文件创建)。

棘手的问题是我在初始化引用的应用程序时(我认为这是问题所在)收到此错误:

收听http://127.0.0.1:7908

handlers$add(handler, key, tail) 出错:键/已在使用中

目前这种闪亮界面的错误超出了我的知识范围。要调试此错误,我需要进行调查。

【讨论】:

    【解决方案2】:

    没有直接的方法可以从另一个闪亮的应用程序中启动闪亮的应用程序。在闪亮的应用程序中调用runApp() 将导致此错误,

    Warning: Error in shiny::runApp: Can't call `runApp()` from within `runApp()`. If your application code contains `runApp()`, please remove it.
    

    但是,对于 RStudio 1.2,有一个解决方法。我们可以将第二个应用程序的runApp() 存储在 R 脚本中,并将此脚本作为单独的 R Studio 作业执行。这将在新会话中启动第二个闪亮的应用程序,而不会停止第一个。

    代码:

    脚本.R

    shiny::runApp(path_to_app, launch.browser = TRUE, port = 875)
    

    ui.R

    actionButton("launch_app", "Launch second Shiny App")
    

    服务器.R

    observeEvent(input$launch_app, {
            rstudioapi::jobRunScript(path = path_to_script)
        })
    

    如果这是一个包,请将脚本存储在 inst/ 中并使用 system.file() 来构建路径。

    【讨论】:

      【解决方案3】:

      不要再次使用 run-app,而是使用 shinyAppDir('path to your new app')。

      这段代码对我有用。 stopApp(shinyAppDir("NewApp/"))

      【讨论】:

        猜你喜欢
        • 2013-07-08
        • 2015-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-20
        • 1970-01-01
        • 2016-05-23
        • 2014-10-28
        相关资源
        最近更新 更多