0

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.

rainer
  • 929
  • 2
  • 14
  • 25
  • 2
    `data` is a reactive function and needs to be called using `data()`. For example `data()$DATE`. Also the `plotdata` call may need to be inside `renderGvis` but I cant test as it stands. – jdharrison Nov 28 '13 at 11:39
  • yes u're right, it needs to be inside `renderGvis`. Thank you very much, it did work – rainer Nov 28 '13 at 11:46

0 Answers0