我有一个 flexdashboard,其中包含上传到服务的 mtcars 数据库的鸭子数据库。问题是它只会显示mtcars
一次数据库。如果我点击刷新或关闭窗口并重新打开,它将不会再次连接到它。我必须重新保存 .Rmd 文件并将其重新上传到服务器(未进行任何更改)。到底是怎么回事?
---
title: "Test"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
library(DBI)
#con <- DBI::dbConnect(duckdb::duckdb(), "DSTLData/FINAL_data.duckdb",read_only=TRUE)
con = dbConnect(duckdb::duckdb(), dbdir=":memory:", read_only=FALSE)
DBI::dbWriteTable(con, "mtcars", mtcars)
onStop(function(){
DBI::dbDisconnect(con)
})
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
vecFun <- renderPrint({ 1:5 })
vecFun()
#a<-dplyr::tbl(con,"mtcars")%>%head(5)# This doesn't work at all
a<-dbGetQuery(con, 'SELECT * FROM mtcars LIMIT 5')
DT::renderDataTable(a)
```