简体   繁体   English

尝试从 R 脚本呈现 shiny flexdashboard 时找不到错误 object output

[英]Getting Error object output not found when trying to render shiny flexdashboard from R script

I have a shiny flexdashboard that runs fine if I open the file directly and click Run Document in R Studio, however I am trying to set up an R script to run the dashboard.我有一个 shiny flexdashboard,如果我直接打开文件并在 R Studio 中单击“运行文档”,它运行良好,但是我正在尝试设置一个 R 脚本来运行仪表板。 The script will find the markdown file and run partly through it but always throws an error once it gets to something like output$something <- renderUI(...) .该脚本将找到 markdown 文件并部分运行它,但一旦它到达类似output$something <- renderUI(...)的地方,它总是会抛出错误。 The error is错误是

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

A test markdown file for this issue is:针对此问题的测试 markdown 文件是:

---
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]]
})


#```

And I've tried to use the following scripts with the same results:我尝试使用以下脚本获得相同的结果:

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

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

For the path I've tried a shared drive path and my desktop and I've tried a number of different arguments that I've read will let the render function know to make a flaexdashboard (in comments in the render function).对于path ,我尝试了一个共享驱动器路径和我的桌面,并且我尝试了一些不同的 arguments,我已经阅读过它们会让渲染器 function 知道制作一个 flaexdashboard(在渲染函数的注释中)。 In all my attempts I get the Error saying that the output object cant be found.在我的所有尝试中,我都收到错误消息,指出output object。 If anyone could offer any help I would greatly appreciate it.如果有人可以提供任何帮助,我将不胜感激。

In flexdashboard you don't need to use output .flexdashboard ,您不需要使用output Just do:做就是了:

---
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]]
})

```

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM