在使用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)
})
})
答案 0 :(得分:2)
主要问题是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")
)
))
答案 1 :(得分:1)
我很确定这不是答案,而是格式化评论。在运行你的代码并且没有输出之后(这看起来并不令人惊讶,因为我看到没有任何命令似乎给出了绘图方向)我使用天气数据运行了这个:
rPlot(MaxTemp ~ Sunshine , data = w, type = 'point')
rPlot(MinTemp ~ Date,
data = w,
type = "line")
让闪亮的服务器将剧情发送到我正在运行的Firefox实例。
sessionInfo()
R version 3.0.0 RC (2013-03-31 r62463)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grDevices datasets splines graphics utils stats methods base
other attached packages:
[1] rattle_2.6.27 rCharts_0.3.51 shiny_0.6.0 rms_3.6-3 Hmisc_3.10-1
[6] survival_2.37-4 sos_1.3-5 brew_1.0-6 lattice_0.20-15
loaded via a namespace (and not attached):
[1] bitops_1.0-5 caTools_1.14 cluster_1.14.4 colorspace_1.2-1
[5] dichromat_2.0-0 digest_0.6.3 ggplot2_0.9.3.1 grid_3.0.0
[9] gtable_0.1.2 httpuv_1.0.6.3 labeling_0.1 MASS_7.3-26
[13] munsell_0.4 plyr_1.8 proto_0.3-10 RColorBrewer_1.0-5
[17] reshape2_1.2.2 RJSONIO_1.0-1 scales_0.2.3 stringr_0.6.2
[21] tools_3.0.0 whisker_0.1 xtable_1.7-1 yaml_2.1.7