Gary
Gary

Reputation: 2167

rChart+nvd3 not showing up - Error: need finite ylim value

I am able to plot my graphs successfully in renderPlot and in ggplot, but using nPlot for rCharts, I am receiving an error code:

Error in plot.window(xlim = xlim, ylim = ylim, log = log, yaxs = pars$yaxs) : 
  need finite 'ylim' values

I only included the code that I know is troublesome: My ui.R:

mainPanel(
     showOutput("plot3", "nvd3")
    ))

My server.R

  output$plot3 <- renderChart({
    candySelect<- input$candy
    d <- candyData[candyData$candy== candySelect, ]
    p3 <- nPlot(freq~purchase_month,  data = d ,group = "candy", type = "lineChart")
    p3$addParams(dom = 'plot3')
    p3
  })

Note: the freq and purchase_month are columns in my dataset. purchase_month is in the format of, for example, "2014/04".

The output looks like this: enter image description here

Upvotes: 0

Views: 145

Answers (1)

Pork Chop
Pork Chop

Reputation: 29387

I think you haven't formatted your dates, you can format your dates using something like dates <- as.Date(dates, "%Y-%M").

rm(list = ls())
library(shiny)
library(rCharts)

# sample Data
dat <- data.frame(
  purchase_month  = seq(as.Date("2014/1/1"), by = "month", length.out = 12), 
  candy = sample(c(rep("Mars",4),rep("Bounty",4),rep("Twix",4))), 
  freq =round(runif(12)*500,0))

#format dates if needs be (they have to be a datetime object)
#dates <- as.Date(dates, "%Y-%M")

ui <- fluidPage(titlePanel("Candy Select"), 
                  sidebarPanel(
                    selectInput("candy", "Choose a candy:", choices = c("Mars", "Bounty","Twix"))),
                mainPanel(showOutput("plot3","Nvd3"))
)

server <- function(input, output) {

  output$plot3 <- renderChart2({
    dat <- dat[dat$candy %in% input$candy,]
    n <- nPlot(freq~purchase_month , group =  'candy', data = dat, type = 'lineChart')

    n$xAxis(tickFormat =   "#!
      function(d) {return d3.time.format('%Y/%m')(new Date(d*1000*3600*24));} !#",rotateLabels = -90 )
    n
  })
}

shinyApp(ui, server) 

The plot shows the frequencies

enter image description here

Upvotes: 1

Related Questions