[EDITED]
我使用rvd包装器为nvd3编写了一个简单的基于Shiny的多棒图表实现。当我从R控制台本地生成图形时,我能够与它进行交互,并且转换按预期工作。但是,当包裹在闪亮的界面中时,它不会重绘,也不允许与绘图本身进行交互。
我已粘贴在下面使用的代码中以及示例数据集。使用示例数据运行时,效果很好。但是,我的实际数据集明显更大(行程数据集中的记录超过5k,站数据集中的条目超过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"
答案 0 :(得分:0)
好吧,我脸上的蛋。 csv文件的最后一行中的一些错误数据破坏了构建。