1

Admittedly, I am a newbie using shiny, however I have a strange error that seems to be coming from ggplot invoked via the SERVER.R file.

The error is Error in exists(name, envir = env, mode = mode) : argument "env" is missing, with no default

I did some searching and found most of the errors attrubuted to faulty ggplot specification... but I cannot find the bug.

Here is my UI.R file:

library(shiny)
shinyUI(pageWithSidebar( 
headerPanel("Applications"),
sidebarPanel(
dateRangeInput('dateRange',
             label = 'Date range input: yyyy-mm-dd',
             start = Sys.Date() - 6, end = Sys.Date()
)
),
mainPanel(plotOutput("monthGraph"))
))

Here is my SERVER.R file:

library("shiny")
library("RMySQL")
library("ggplot2")
#con <- dbConnect(MySQL(), host="***", port= 3306, user="***", password = "****", dbname="data")
#query  <- dbGetQuery(con, "select date(datetime_var) as date , value
#from table
#where value= 1")

query <- data.frame(date=seq(as.Date("2014-01-01"), as.Date("2014-01-07"), 1), value=c(1:7))


shinyServer(function(input, output, session) { 

passData <- reactive({
query <- query[query$date %in% seq.Date(input$dateRange[1], input$dateRange[2], by="days"),]
query
})


output$monthGraph <- renderPlot({



graphData <- passData()

theGraph <- ggplot(graphData, 
               aes(x=date)) +
               geom_bar(stat="bin") +
               ylab("Count")

print(theGraph)
})
})

So, I'm attempting to create a shiny app that dynamically updates based a simple bar graph on the users input of dateRange...

gh0strider18
  • 1,140
  • 3
  • 13
  • 23
  • It would help if you included a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Since we don't have access to your data base, we can't run the code. If the error does not depend on accessing the DB, then include a sample data set in the code. It is much easier to help you if the code you share is runnable so we can re-create the exact same error as you. Are you even including the `ggplot2` library? – MrFlick Jan 08 '15 at 19:38
  • @MrFlick I didn't have `ggplot2` called - but it was called in my local environment. I've made the edit. I've also added some simple bunk data that replicates the bug. It's also in my edited post. Any help you can lend would be very much appreciated. – gh0strider18 Jan 08 '15 at 20:36

1 Answers1

1

Your error is reproduced when you have empty graphData. I would suggest to add if (nrow(graphData)==0) return() after graphData <- passData() to fix your problem.

Marat Talipov
  • 13,064
  • 5
  • 34
  • 53