我正在尝试将 Shiny 应用程序保存在 Rmarkdown 文件中作为独立的 HTML 页面。
我可以用一个简单的 DT::datatable() 来做到这一点:
---
title: "Test4"
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r t4, echo=FALSE, message=FALSE, echo=FALSE}
DT::datatable(iris)
后跟
rmarkdown::render(input = "Test4.Rmd", output_file = "Test4.html", runtime = "shiny")
为我提供了一个包含 iris 数据集的 html 文件,我可以根据需要将其粘贴到文件服务器上。 $Employer
喜欢它,并感谢 Joe Cheng 等人向我指出了这个解决方案。
(
此外,Joe Cheng 在 Google Shiny 群组上发送了以下内容:
如果您只有DT::datatable()
对象(称之为“x”),那么你可以调用 htmlwidgets::saveWidget(x, "filepath.html")
将其另存为 HTML 页面
)
但是,$employer
现在要求我将其中两个以选项卡式格式放在一起。
当我使用此代码时,如果我使用 RStudio 中的“运行文档”,Rmd 页面将正确呈现:
---
title: "Test3"
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Embedded Application
Test To Try and Render This Out As Standalone Tabbed Shiny App With Two DT::Dataframes.
```{r tabsets, echo=FALSE, warning=FALSE, message=FALSE}
shinyApp(
ui <- (
navbarPage(
title = 'Testing Saving Shiny',
tabPanel('MTCars', DT::dataTableOutput('mtcarz')) ,
tabPanel('Irises', DT::dataTableOutput('iriz'))
)
)
,
server <- (function(input, output) {
output$mtcarz <- DT::renderDataTable({
DT::datatable(
mtcars,
escape = FALSE,
rownames = FALSE,
options = list(
pageLength = 25,
autoWidth = TRUE
)
)
})
output$iriz <- DT::renderDataTable({
DT::datatable(
iris,
escape = FALSE,
rownames = FALSE,
options = list(
pageLength = 25,
autoWidth = TRUE
)
)
})
})
)
```
但是当我在其上使用 rmarkdown::render 时,HTML 页面会为我提供预期的框架(标题等),但其中没有任何选项卡/数据框。
我正在使用 DT 的 v.1、rmarkdown 的 v.0.9.2 和 Shiny 的 v.0.12.2 以及 R 3.2.1。
最佳答案
我可能错过了一些东西,但我不知道 Shiny
应用程序可以在没有 Shiny
服务器的情况下运行。这会是动态的吗?如果没有,你可以这样做。
```{r echo = FALSE, warning = FALSE}
library(shiny)
navbarPage(
title = 'Testing Saving Shiny',
tabPanel('MTCars', DT::datatable(
mtcars,
escape = FALSE,
rownames = FALSE,
options = list(
pageLength = 25,
autoWidth = TRUE
)
)),
tabPanel('Irises', DT::datatable(
iris,
escape = FALSE,
rownames = FALSE,
options = list(
pageLength = 25,
autoWidth = TRUE
)
))
)
```
关于r - 在 Rmarkdown 中保存导航栏 Shiny 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34818118/