尝试从R脚本渲染闪亮的Flexdashboard时找不到错误对象输出

时间:2020-11-12 19:42:36

标签: r shiny flexdashboard

如果我直接打开文件并单击R Studio中的“运行文档”,我会有一个闪亮的flexdashboard,可以正常运行,但是我试图设置一个R脚本来运行仪表板。该脚本将找到markdown文件并部分运行该文件,但是一旦到达output$something <- renderUI(...)之类的文件,总会引发错误。错误是

Error in output$select_file <- renderUI({ : object 'output' not found

此问题的测试降价文件为:

---
title: "example"
author: "hamburglar"
output: 
  flexdashboard::flex_dashboard:
    theme: yeti
    orientation: rows
    vertical_layout: fill
runtime: shiny
---

#```{r setup, include=FALSE}

library(flexdashboard)
library(tidyverse)

#```

Home
=======================================================================

Sidebar {.sidebar}
-----------------------------------------------------------------------

> These are some notes

#```{r}

data(iris)
data(cars)
data(CO2)
files <- list(iris=iris, cars=cars, CO2=CO2)

output$select_file <- renderUI({
  selectInput(inputId='file_choice', 
              label='Choose File', 
              choices=names(files)
              )
})

uiOutput("select_file")

#```

Row
-----------------------------------------------------------------------

### Data
#```{r}

renderTable({
  files[[input$file_choice]]
})


#```

并且我尝试使用以下脚本获得相同的结果:

library(flexdashboard)
library(shiny)
library(rmarkdown)

render("path/test_board.Rmd", 
  #output_file="Dashboard.html"
  #flex_dashboard()
  #"flex_dashboard"
)

对于path,我尝试了共享驱动器路径和台式机,并且尝试了许多不同的参数,这些参数将使render函数知道创建flaexdashboard(在渲染功能)。在所有尝试中,我都收到一条错误消息,说找不到output对象。如果有人可以提供任何帮助,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

flexdashboard中,您无需使用output。只要做:

---
title: "example"
author: "hamburglar"
output: 
  flexdashboard::flex_dashboard:
    theme: yeti
    orientation: rows
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}

library(flexdashboard)
library(tidyverse)

```

Home
=======================================================================

Sidebar {.sidebar}
-----------------------------------------------------------------------

> These are some notes

```{r}

data(iris)
data(cars)
data(CO2)
files <- list(iris=iris, cars=cars, CO2=CO2)

selectInput(inputId='file_choice', 
              label='Choose File', 
              choices=names(files)
              )

```

Row
-----------------------------------------------------------------------

### Data
```{r}

renderTable({
  files[[input$file_choice]]
})

```

result