我想在另一个 vanilla 闪亮应用程序中嵌入一个外部闪亮应用程序,然后在本地计算机上运行该应用程序,包括嵌套/嵌入式应用程序。
在RMarkdown中,这是well documented,可以通过在flexdashboard的R块中使用shinyAppDir()
来轻松实现。
我的问题是:如何在纯净的香草光泽环境下完成此操作(不依赖RMarkdown和flexdashboard)?我尝试了将shinyAppDir
放在renderUI
语句中的尝试,但这没有用(这很有意义,因为该应用程序不仅由UI组成,而且还包含服务器逻辑)。 / p>
以下是在flexdashboard中嵌入式闪亮应用程序的工作示例:
这是我要嵌入的简单闪亮应用程序:
library(shiny)
library(dplyr)
shinyApp(ui = fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
textInput("min_e", "min eruptions", min(faithful$eruptions)),
textInput("max_e", "max eruptions", max(faithful$eruptions)),
actionButton(inputId = "OK", label = "OK")
),
mainPanel( plotOutput("distPlot1")
)
)
),
server = function(input, output) {
nbins = reactive({input$OK
isolate(input$bins)})
faithful_filtered = reactive({input$OK
faithful %>% filter(eruptions >= isolate(input$min_e),
eruptions <= isolate(input$max_e))
})
output$distPlot1 <- renderPlot({
x <- faithful_filtered()[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = nbins() + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
)
它可以像这样嵌入在flexdashboard中(如果运行此代码,请确保首先将上面的应用程序保存为app.R,然后在shinyAppDir()
中输入正确的文件路径)。
---
title: "embedded shiny"
output:
flexdashboard::flex_dashboard:
orientation: column
runtime: shiny
---
```{r, include=FALSE, message=FALSE, context="setup"}
library(flexdashboard)
library(shiny)
```
Input {.sidebar data-width=300}
-------------------------------------
```{r, echo=FALSE, context="render"}
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
actionButton(inputId = "OK", label = "OK")
```
```{r, context="server"}
```
Row
-----------------------------------------------------------------------
### Some plot here
```{r, context="server"}
```
```{r, echo=FALSE}
```
### Another plot here
```{r, context="server"}
```
```{r, echo=FALSE}
```
### Embeded app here
```{r, echo=FALSE}
shinyAppDir(
file.path("file_path_goes_here"), # enter valid file path here
options=list(
width="100%", height=700
)
)
```