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

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

我能够在 renderPlotggplot 中成功绘制图表,但是使用 nPlot 作为 rCharts,我收到错误代码:

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

我只包含了我知道很麻烦的代码: 我的 ui.R:

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

我的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
  })

注意:freqpurchase_month 是我数据集中的列。 purchase_month 格式如"2014/04".

输出如下所示:

我认为你还没有格式化你的日期,你可以使用类似 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) 

图中显示了频率