SQLite 和 Shiny/flexdashboard:无法在 SQL 查询中嵌入 reactiveValues() 对象

SQLite and Shiny/flexdashboard: Cannot embed a reactiveValues() object in a SQL query

我正在尝试过滤 sqlite3 数据库和 print/plot 结果数据。例如。 nycflights13::weather 数据。但是在 flexdashboard 环境中,它抱怨无法在 SQL 查询中嵌入反应对象。这是否意味着我不能将 SQLite 与 flexdashboard 一起使用?

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(DBI)
library(dplyr)
library(tidyr)
library(pool)

con <- dbConnect(RSQLite::SQLite(), dbdir=":memory:")
DBI::dbWriteTable(con, "weather", nycflights13::weather)
bigdf<-tbl(con, "weather")
```

Column {.sidebar}
----------------------------
```{r}

selectInput("year", label = "year :",
            choices = c(2012,2013,2010))
```


Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
a<-reactive({
  a<-
   bigdf%>% 
    filter(origin=="EWR" & year == as.integer(input$year)) %>%
    head(25)%>%
    collect()
})
renderTable(a())
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

```{r}
reactive({
  plot(a()$year,a()$wind_speed)
})
```

我稍微调整了代码以按照建议使用 !! 修复程序,并使 b 绘图成为一个反应对象,然后可以通过调用 renderPlot 来呈现该对象.


title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(DBI)
library(dplyr)
library(tidyr)
library(pool)

con <- dbConnect(RSQLite::SQLite(), dbdir=":memory:")
DBI::dbWriteTable(con, "weather", nycflights13::weather)
bigdf<-tbl(con, "weather")
```

Column {.sidebar}
----------------------------
```{r}
selectInput("year", label = "year :",choices = c(2013,2012,2010),selected = 2013)
```


Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
a <- reactive({
    a <-
      bigdf %>% 
      filter(origin=="EWR" & year == as.integer(!!input$year)) %>%
      head(25) %>%
      collect()
    a  # make sure to return something
})
renderTable(a())
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

```{r}
b <- reactive({  # make the plot a reactive object
  plot(a()$year, a()$wind_speed)
})
renderPlot(b()) # then render it
```

此处显示结果。