在两个闪亮的应用程序之间切换

时间:2018-01-23 08:19:18

标签: r shiny

所以我在函数内部有两个独立的onefile shinyApps,其中包含UI和Server。

现在我需要做的是在第一个应用程序中调用第二个应用程序。

这是一个简单的例子(简化了函数以显示我想要实现的功能):

appOne <- function() {
  app <- list(ui = NULL, server = NULL)
  app$ui <- fluidPage(fluidRow(
    column(3),
    mainPanel(h2("Welcome to the load page"),actionButton("browse", strong("Browse Variants"), class = "btn-success")))
  )
  app$server <- function(input, output, session) {
    observeEvent(input$browse, {
      appTwo()
    })
  }
  runApp(app)
}

appTwo <- function() {
  app <- list(ui = NULL, server = NULL)
  app$ui <- fluidPage(fluidRow(
    column(3),
    mainPanel(h2("Welcome to appTwo"), plotOutput("plot")))
  )
  app$server <- function(input, output, session) {
    output$plot <- renderPlot({
      plot(cars)
    })
  }
  runApp(app)
}

所以我需要的是当用户点击第一个应用程序中的按钮时切换到第二个应用程序。有什么想法吗?

4 个答案:

答案 0 :(得分:0)

您可以使用iframe来执行此操作:

rm(list = ls())
library(shiny)

ui <- fluidPage(
  column(2,selectInput("Apps", label="Choose an app",choices=c('App1','App2'))),
  column(12, div(style="width: 100%;height: 100%;",htmlOutput("frame")))
)

server <- function(input, output, session) {

  output$frame <- renderUI({
    if(input$Apps == "App1"){
      address <- "https://shiny.rstudio.com/gallery/genome-browser.html"
    }
    if(input$Apps == "App2"){
      address <- "https://shiny.rstudio.com/gallery/superzip-example.html"
    }
    my_test <- tags$iframe(src=address,height = 1200,width = "100%")
    my_test
  })
}

shinyApp(ui, server)

答案 1 :(得分:0)

除了将每个应用程序运行到模块中,我看不到其他方法。只需将ui作为函数调用,然后通过callModule()调用服务器即可完成(请参阅有关模块化的大量文章)。另外,您可以使用调用单个模块的主脚本将每个应用程序重新编写为独立应用程序。最后,您可以通过多种方式在应用程序之间进行切换:将selectInput()renderUI()结合使用即可完成工作。

答案 2 :(得分:0)

我正面临着同样的问题。这是我的解决方案。它需要使用较大的独立应用程序进行测试,但这听起来可以回答您的问题。

我添加了选择器应用程序(称为appRoute,但实际上路由功能是由无限循环确保的)。每个应用程序都需要有一个退出按钮。应用程序通过其返回/停止代码(发光的stopApp函数)进行通信。闪亮的打印功能正在调用闪亮的runApp函数。

应该可以通过将其他按钮链接到特定的stopApp来在应用程序之间切换(不返回选择器应用程序)。我不知道是否可以在应用程序之间传送信息(也许使用会话),但是我将为此使用磁盘文件。

让我知道您是否找到了更好的解决方案。

 public function boot()
{
    \Storage::extend("google", function ($app, $config) {
        $client = new \Google_Client;
        $client->setClientId($config['clientId']);
        $client->setClientSecret($config['clientSecret']);
        $client->refreshToken($config['refreshToken']);
        $service = new \Google_Service_Drive($client);
        $adapter = new GoogleDriveAdapter($service, $config['folderId']);
        return new Filesystem($adapter);
    });

}

答案 3 :(得分:-3)

通过使用反应功能和切换按钮,您可以从一个应用程序转到其他应用程序,而无需两个不同的应用程序。试着在一个应用程序中编写所有内容。它会起作用

相关问题