I'm trying to build a shiny app to plot some data which I get from a database. Below are my ui.R and server.R files. The problem is the plot won't work, I always get an error like:
Error in data$DATE : object of type 'closure' is not subsettable
ui.R:
library(shiny)
shinyUI(pageWithSidebar(
# Application title
headerPanel("TEST1234"),
sidebarPanel(
selectInput("choice", "Choose a Code:",
choices = c("123", "124", "125")),
dateInput("sdate","Startdate",value="2013-01-01",min="2013-01-01"),
dateInput("edate","Enddate"),
submitButton(text="Start")),
mainPanel(
tabsetPanel(
tabPanel("Plot",h4("Plot"),htmlOutput("plot"))
)
)
))
server.R
library(shiny)
library(RODBC)
library(googleVis)
shinyServer(function(input,output){
data<-reactive({
connection <- odbcConnect("DB", uid="user",pwd="pw");
sql<-"select * from data where code='mycod' order by date desc"
sql<-gsub("mycod",input$coice,sql)
data <- sqlQuery(connection,sql,dec=",");
})
plotdata<-data.frame(DATE=data$DATE,DATA=round(data$values*100,2))
output$volaplot<-renderGvis({
return(gvisLineChart(plotdata,xvar="DATE",options=list(title="Test Plot")))
})
odbcCloseAll()
})
The output of the db-query is a data.frame with two columns, a date column and the corresponding values, which I want to plot afterwards. Thanks in advance.