在使用 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 调用,都需要引用相同的 plot 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")
)
))
关于R:rCharts 和 Shiny:人力车图不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17411584/