我有一个简单的线性模型保存为.rda
文件,我想将其导入并应用于闪亮的flexdashboard的一组输入。
我的代码如下:
---
title: "Where Should I Publish My Piece?"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
load('mods/mod.rda') # The lm() being imported
load('sections_list.rda') # A list of sections
```
Sidebar {.sidebar}
-----------------------------------------------------------------------
### Article Info
```{r}
renderText("Tell us a few things about your thing")
textInput(inputId = 'a',
label = 'What's a number?',
value = 1000)
selectInput(inputId = 'b',
label = 'What section are you using?',
choices = secs,
selected = secs[1])
selectInput(inputId = 'c',
label = 'What hour is it?',
choices = seq(0,23,1),
selected = 0)
selectInput(inputId = 'd',
label = 'What day of the week is it?',
choices = c("Thursday","Friday", "Saturday", "Sunday",
"Monday", "Wednesday", "Tuesday"),
selected = "Monday")
```
Columns {data-width=650}
-----------------------------------------------------------------------
### Predictions
```{r}
newdat <- reactive({
predict(mod,
newdata = data.frame(word_count = input$a,
section = input$b,
pub_hour = input$c,
dow = input$d))
})
renderTable({newdat})
```
我收到以下错误:
cannot coerce class "c("reactiveExpr", "reactive")" to a data.frame
我该怎么做才能解决这个问题?如果我想稍后newdat
以及renderPlot({ggplot(newdat, yadayada)+geoms})
之类的内容,那么这也是可能的吗?
答案 0 :(得分:2)
您没有在renderTable中调用newdat的反应式表达式。由于您将其设置为被动,因此您需要使用newdat():
renderTable({
newdat()
})