5

在使用 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)    
  })  
})
4

2 回答 2

2

主要问题是showOutputrenderChartShiny 调用都需要引用相同的 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")
  )
))
于 2013-07-02T02:12:22.930 回答
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        
于 2013-07-01T19:52:46.887 回答