【发布时间】:2015-07-22 11:12:33
【问题描述】:
我最近开始使用 dygraph,到目前为止我非常喜欢它。我曾尝试在闪亮的情况下使用它,但没有取得多大成功。虽然我的脚本没有产生任何错误,但它也没有产生任何图表!
你有没有机会指引我正确的方向?
这是我的数据示例:
> head(df2)
date Variety Count Price Value Quantity TotalKg
1 2014-11-06 CRIPPS PINK 80-90 204 3670 18 333
2 2014-11-06 CRIPPS PINK 120-135 181 10150 56 1036
3 2014-11-06 CRIPPS RED 80-90 221 26910 122 2257
4 2014-11-06 CRIPPS RED 100-110 205 22910 112 2072
5 2014-11-06 CRIPPS RED 120-135 193 58950 306 5661
6 2014-11-06 TOPRED 80-90 167 7350 44 814
使用 Variety 和 Count 变量,我想绘制一段时间内的价格图表。
这是我的 ui.R
library(dygraphs)
library(shiny)
shinyUI(fluidPage(
titlePanel("Apples Prices"),
sidebarLayout(
sidebarPanel(
selectInput("productname", "Select your product",
choices = levels(df2$Variety)),
selectInput("count", "Select your size",
choices = levels(df2$Count))),
mainPanel(
dygraphOutput("applesgraph"))
)))
和服务器端:
library(shiny)
library(dygraphs)
library(dplyr)
library(xts)
shinyServer(function(input, output) {
dfa <- reactive({df2 %>% filter(Variety == input$productname &
Count == input$count )})
#the first graph which is price over time (input: variety, count, date)
output$applesgraph <- renderDygraph({
xts(dfa()$Price, order.by = dfa()$date) %>% dygraph()
})
})
我能感觉到我对 dplyr 和时间序列对象的方法有误......那我应该什么时候过滤?我尝试了很多组合,但是我总是遇到诸如“不可子集”之类的错误。
提前感谢您能给我的任何光线/方向。
【问题讨论】:
-
您的应用程序一切正常。您的问题似乎来自您的数据输入。您能否以某种方式提供您正在使用的数据或更具有代表性的样本? (这里只给了一个日期,所以在X轴上用起来不太方便)
-
你能不能打电话给
dput(df2),比如把内容粘贴到pastebin.com。str(df2)没有帮助 -
如果您需要,这里是整个文件的链接:drive.google.com/a/ifitwala.com/file/d/…
-
好吧,我不知道该说什么...一切都与您的代码完美配合。当我用你的数据测试它时,我可以看到这些变化和预期的输出变化。您能否尝试更新您的 dygraph、dplyr、shiny 软件包,看看是否能解决问题?