[編集]
nvd3 の rcharts ラッパーを使用して、マルチバー チャートの単純な Shiny ベースの実装をコーディングしています。R コンソールからローカルでグラフィックを生成すると、それを操作でき、トランジションが期待どおりに機能します。ただし、光沢のあるインターフェイスにラップすると、再描画されず、プロット自体との対話も許可されません。
以下で使用しているコードとサンプル データ セットを貼り付けました。サンプルデータで実行すると、うまく機能します。ただし、実際のデータ セットはかなり大きくなっています (トリップ データセットに 5,000 レコード以上、ステーション データセットに 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"