2

[编辑]

我一直在使用 nvd3 的 rcharts 包装器编写一个简单的基于 Shiny 的多条形图实现。当我从 R 控制台本地生成图形时,我能够与之交互,并且转换按预期工作。但是,当包裹在闪亮的界面中时,它不会重绘,也不允许与绘图本身进行交互。

我已经粘贴了我在下面使用的代码以及示例数据集。使用示例数据运行时,效果很好。但是,我的实际数据集要大得多(trips 数据集中有超过 5k 条记录,stations 数据集中有超过 100 个条目)。不知道为什么这很重要,但它似乎破坏了界面。

这是 global.r 文件:

#global.r

preppedTrips <- read.csv("trips.csv")
stations <- read.csv("stations.csv")
stationnames <- as.character(stations$Name)

这是 server.r 文件:

#ui.r 
require(rCharts)

shinyServer(function(input, output) { 

  trips <- reactive({
    preppedTrips[preppedTrips$station == stationID(),]
  })

  stationID <- reactive({
    a <- as.character(stations[stations$Name == input$station,]$ID)
  })

  output$caption <- renderText({
    paste("Station ID is: ", stationID(), sep="")
  })

  output$plot <- renderChart({  
    n1 <- nPlot(value ~ time, group="group", data = trips(), type="multiBarChart")
    n1$set(dom = "plot")
    return(n1)
  })
})

这是 ur.r 文件:

require(rCharts)
shinyUI(pageWithSidebar(
  headerPanel("nvd3 test"),

  sidebarPanel(
    selectInput(inputId = 'station',
      label = "Stations",
      choices = stationnames,
      selected = 's1'),

    submitButton("Update View")
  ),

  mainPanel(
    h3(textOutput("caption")), 

    showOutput("plot","nvd3")
  )
))

以下是 trips.csv 文件的示例:

"","time","variable","value","group","station"
"8","07:00","V1",73,"Start","s1"
"9","08:00","V1",145,"Start","s1"
"10","09:00","V1",146,"Start","s1"
"11","10:00","V1",85,"Start","s1"
"12","11:00","V1",84,"Start","s1"
"13","12:00","V1",102,"Start","s1"
"14","13:00","V1",126,"Start","s1"
"32","07:00","V1",27,"End","s1"
"33","08:00","V1",97,"End","s1"
"34","09:00","V1",148,"End","s1"
"35","10:00","V1",70,"End","s1"
"36","11:00","V1",106,"End","s1"
"37","12:00","V1",84,"End","s1"
"38","13:00","V1",124,"End","s1"
"55","07:00","V1",24,"Start","s2"
"56","08:00","V1",107,"Start","s2"
"57","09:00","V1",127,"Start","s2"
"58","10:00","V1",54,"Start","s2"
"59","11:00","V1",50,"Start","s2"
"60","12:00","V1",59,"Start","s2"
"61","13:00","V1",45,"Start","s2"
"78","07:00","V1",34,"End","s2"
"79","08:00","V1",101,"End","s2"
"80","09:00","V1",95,"End","s2"
"81","10:00","V1",54,"End","s2"
"82","11:00","V1",44,"End","s2"
"83","12:00","V1",60,"End","s2"
"84","13:00","V1",56,"End","s2"

这是stations.csv 文件的示例:

"","Name","ID"
"1","Station 1","s1"
"2","Station 2","s2"
4

1 回答 1

0

好吧,我脸上的鸡蛋。csv 文件最后一行中的一些错误数据破坏了构建。

于 2013-08-14T20:29:55.990 回答