【问题标题】:rChart+nvd3 not showing up - Error: need finite ylim valuerChart+nvd3 未显示 - 错误:需要有限的 ylim 值
【发布时间】:2015-10-16 13:21:56
【问题描述】:

我能够在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")
    ))

我的服务器.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”。

输出如下所示:

【问题讨论】:

  • 请检查您的input$ 值是否为空
  • 我可以这样做吗:d[!is.na(d)]
  • 你应该检查is.null(input$candy) 默认他们设置为NULL
  • 好的,我应该删除它们吗is.null 返回TRUE

标签: r shiny rcharts


【解决方案1】:

我认为您还没有格式化日期,您可以使用 dates &lt;- 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) 

图表显示频率

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 2014-11-10
    • 2016-09-06
    相关资源
    最近更新 更多