1

I started building my first shiny app and it ended up being more complicated than expected (learning!). Unfortunately, I've managed to Google-fu a ton of little errors into a situation in which there are no errors, it just returns a blank graph.

The Code: (server)

library(ggplot2)
library(Quandl)
library(methods)

shinyServer(
  function(input, output) {
# see (https://stackoverflow.com/questions/22834778/r-shiny-daterangeinput-format)

start_date2<-reactive({format(input$date_range[1])})
end_date2<-reactive({format(input$date_range[2])})

psuedonym<-data.frame(Date=as.Date(character()),
                      Value=integer(),
                      stringsAsFactors=FALSE)

psuedonym<-reactive({Quandl("ZILL/Z94550_A", start_date2, end_date2, type="raw")})

output$qplot<-renderPlot({reactive({plot(psuedonym$Date, psuedonym$Value)})})
})

(ui)

library(shiny)
shinyUI(fluidPage(
    titlePanel("My Shiny App"),

    sidebarLayout(position="right", 
        sidebarPanel(
        plotOutput("qplot")
        ),
    mainPanel(dateRangeInput("date_range", 
        label=h3("Date Range"), start="2010-01-01", end="2015-01-01",
    )
))))

What I want: I want the user to be able to input dates in the Date Range, input those variables into the Quandl code (https://www.quandl.com/help/r), and then pull that data for them and generate a simple graph. Later on I'd like to add the ability to define the zip code and the variables. This, for example, works:

library(ggplot2)
library(Quandl)
library(methods)

shinyServer(
  function(input, output) {

    start_date="2010-01-01"
    end_date="2015-01-01"
    psuedonym=Quandl("ZILL/Z90001_A", start_date, end_date, type="raw")
    output$qplot<-renderPlot({plot(psuedonym)})

What I think is going wrong: This(R: error in qplot from ggplot2: argument "env" is missing, with no default) and a previous error message makes me think that something has gone wrong with the data frame, that it's not getting the Quandl data somehow.

Thanks in advance for any help

Community
  • 1
  • 1
William
  • 13
  • 1
  • 6

1 Answers1

2

i think you misunderstand how shiny works.

Have a look this tutorial. http://shiny.rstudio.com/tutorial/lesson4/

ui.R

shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(dateRangeInput("date_range", label=h3("Date Range"),start="2010-01-01", end="2015-01-01")
    ),
    mainPanel(
      plotOutput("qPlot")
    )
  )
))

server.R

shinyServer(function(input, output) {
  output$qPlot <- renderPlot({ 
    psuedonym<-Quandl("ZILL/Z94550_A", input$date_range[1], input$date_range[2], type="raw")
    plot(psuedonym)
  }) 
}
)
vck
  • 827
  • 5
  • 10