2

我正在尝试将一个闪亮的应用程序保存在 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 和闪亮的 v.0.12.2 以及 R 3.2.1。

4

1 回答 1

2

我可能遗漏了一些东西,但我不知道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
    )
  ))
)
```
于 2016-02-03T14:47:03.120 回答