我正在尝试创建一个程序来获取用户从选择输入(pnum)中选择的患者数据。我正在尝试向pdata添加一个新列stampDate,尽管当我运行它时:
library(shiny)
require(RODBC)
library(ggplot2)
library(quantmod)
library(reshape)
shinyServer(function(input, output) {
chan1 <- reactive({odbcConnect('database', uid='username')})
queryString1 <- reactive({sprintf("SELECT PatientNum, TimeStamp as Time_Stamp, SWStatus,SWMeanQoS1 as EMAT,SWS3DisplayValue as S3,SWS4DisplayValue as S4,SysDysIndexNoEFLR as SDI
FROM Biometrics..WcdHeartSounds
WHERE PatientNum = ",input$pnum)})
output$pdata <- renderDataTable({
rdata <- reactive({sqlQuery(chan1(), queryString1())})
})
odbcCloseAll()
pdata$stampDate <- as.Date(pdata$Time_Stamp, "%y-%m-%d")
})
我收到此错误消息:
Error in pdata$Time_Stamp : object of type 'closure' is not subsettable
我是否应该在全球环境中使数据表pdata可访问,并在每次用户输入新患者时更新数据表,或者是否还有其他方式对其进行子集,而它仍然只是一个反应函数?我是RStudio和Shiny的新手,在我的工作场所没有人帮助我,所以非常感谢任何帮助。
答案 0 :(得分:0)
首先,检查您的数据框,但未通过sprintf()中的%d
:
sprintf("SELECT PatientNum, TimeStamp as Time_Stamp, SWStatus,
SWMeanQoS1 as EMAT,SWS3DisplayValue as S3,SWS4DisplayValue as S4,
SysDysIndexNoEFLR as SDI FROM Biometrics..WcdHeartSounds
WHERE PatientNum = %d;", input$pnum)
另外,请考虑在renderDataTable({})
rdata <- reactive({sqlQuery(chan1(), queryString1())})
rdata$stampDate <- as.Date(rdata$Time_Stamp, "%y-%m-%d")
output$pdata <- renderDataTable({rdata})