我想在dbgetquery((中包含一个文本输入作为查询的一部分。它显示了正常r脚本的结果,但显示了Rendertable((。
中的错误library(flexdashboard)
suppressWarnings(library(ROracle, quietly = TRUE))
library(shiny)
Column {data-width=350}
-----------------------------------------------------------------------
textInput(inputId = 'Col', label = 'COL', value = "")
actionButton('submit', 'Submit', icon = icon('refresh'))
Column {data-width=650}
-----------------------------------------------------------------------
session <- observeEvent(input$submit, {
etf_con<- dbConnect(drv, username = load.schema.username, password = load.schema.password, dbname = load.schema.database)
t <- dbGetQuery(etf_con, paste0("select * from table_name where col = '", input$Col, "'"))
})
renderTable({
t
})
第二列中的错误是:
无法迫使类"函数"'data.frame
我还尝试过删除observeEvent
,并且只有renderTable
。这样:
renderTable({
etf_con<- dbConnect(drv, username = load.schema.username, password = load.schema.password, dbname = load.schema.database)
dbGetQuery(etf_con, paste0("select * from table_name where col = '", input$Col, "'"))
})
当我点击"运行文档"时,列名在右列中显示。放入文本输入后,有一个错误:
二进制运算符的非数字论点
看起来我需要一个占位符的反应性值,因此我只是添加了 v <- reactiveValues(t = NULL)
,然后使用 t
作为列表 v
中的元素之一。这是链接http://shiny.rstudio.com/articles/action-buttons.html。我使用了图案3。
library(flexdashboard)
suppressWarnings(library(ROracle, quietly = TRUE))
library(shiny)
Column {data-width=350}
-----------------------------------------------------------------------
textInput(inputId = 'Col', label = 'COL', value = "")
actionButton('submit', 'Submit', icon = icon('refresh'))
Column {data-width=650}
-----------------------------------------------------------------------
v <- reactiveValues(t = NULL)
observeEvent(input$submit, {
etf_con<- dbConnect(drv, username = load.schema.username, password = load.schema.password, dbname = load.schema.database)
v$t <- dbGetQuery(etf_con, paste0("select * from table_name where col = '", input$Col, "'"))
})
renderTable({
v$t
})