在使用ggplot2掌握了基本的光泽功能之后,我正在尝试rCharts。但是,我无法显示人力车图。任何帮助,不胜感激;放轻松-我只是习惯了;)
### ui
library(shiny)
require(devtools)
install_github('rCharts', 'ramnathv')
# moved from lower down so call to `showOutput` would not fail
library(rCharts)
library(rattle)
shinyUI(
pageWithSidebar(
headerPanel("Rickshaw test"),
sidebarPanel(
selectInput("variable",
"Choice is arbitrary:",
c("Choice 1", "Choice 2")
)
),
mainPanel(
showOutput("plot", "Rickshaw")
)
)
)
### server
data(weather)
w = weather
dateToSeconds = function (date) {
date = as.POSIXct(as.Date(date), origin = "1970-01-01")
as.numeric(date)
}
w$Date = dateToSeconds(w$Date)
shinyServer(function(input, output) {
output$mpgPlot = renderChart({
rs = Rickshaw$new()
rs$layer(MinTemp ~ Date,
data = w,
type = "line")
return(rs)
})
})
最佳答案
主要问题是showOutput
,renderChart
和Shiny调用都需要引用相同的图ID。我基于此修改了您的代码,它可以正常工作。这是供大家引用的代码
更新。请确保您已从github安装了最新版本的rCharts。
## server.R
library(shiny)
library(rCharts)
library(rattle)
data(weather)
w = weather
dateToSeconds = function (date) {
date = as.POSIXct(as.Date(date), origin = "1970-01-01")
as.numeric(date)
}
w$Date = dateToSeconds(w$Date)
shinyServer(function(input, output) {
output$plot = renderChart({
rs = Rickshaw$new()
rs$layer(MinTemp ~ Date, data = w, type = "line")
rs$set(dom = "plot")
return(rs)
})
})
## ui.R
library(shiny)
library(rCharts)
library(rattle)
shinyUI(pageWithSidebar(
headerPanel("Rickshaw test"),
sidebarPanel(
selectInput("variable", "Choice is arbitrary:",
c("Choice 1", "Choice 2")
)
),
mainPanel(
showOutput("plot", "Rickshaw")
)
))