2017-12-20 30 views
1

간단한 선형 모델을 .rda 파일로 저장하여 가져오고 반짝이는 플렉스 대쉬 보드의 입력 세트에 적용하고 싶습니다.반짝이는 앱에 lm() 모델 적용

내 코드는 다음과 같습니다 : 나는이 문제를 해결하기 위해 할 수있는 일 cannot coerce class "c("reactiveExpr", "reactive")" to a data.frame

:

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

나는 다음과 같은 오류를 받고 있어요? 나중에 newdat을 그려보고 싶다면 (renderPlot({ggplot(newdat, yadayada)+geoms})과 같이) 그렇게 할 수 있습니까?

+2

는'renderTable이어야한다 ({newdat()})'나는 재미 새로운 오류에 저를 얻었다 – Chris

+0

생각합니다. 이제'factor pub_hour has new level 0'을 얻었습니다. – Josh

+1

신경 쓰지 마세요. 그것은 무관 ​​한 문제였습니다. 고마워, 크리스! – Josh

답변

2

당신은 renderTable에서 newdat의 반응식을 호출하지 않습니다. 당신이 그것을 무효로 설정하기 때문에, 당신은) (newdat를 사용해야합니다 :

renderTable({ 
newdat() 
})