Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: rCharts and Shiny: Rickshaw plot won't show

After having a lot of fun getting the basic of shiny down using ggplot2, I'm trying out rCharts. However, I can't get the Rickshaw graph to display. Any help much appreciated; take it easy - I'm just getting use to this ;)

### 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)    
  })  
})
like image 769
user32259 Avatar asked Oct 22 '22 06:10

user32259


2 Answers

The main issue is that showOutput, renderChart and the Shiny call, all need to refer to the same plot id. I modified your code based on this and it works. Here is the code for everyone's reference

UPDATE. Please make sure that you have the latest version of rCharts installed from github.

## 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")
  )
))
like image 107
Ramnath Avatar answered Oct 24 '22 10:10

Ramnath


I'm fairly sure this is not the answer but rather a comment with formatting. After running your code and getting no output (which didn't seem surprising, since I saw no command that appear to give any direction to do plotting) I ran this using the weather data:

rPlot(MaxTemp ~ Sunshine , data = w, type = 'point')

rPlot(MinTemp ~ Date,
         data = w,
         type = "line")

And got the shiny server to send plots to my running instance of 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        
like image 43
IRTFM Avatar answered Oct 24 '22 11:10

IRTFM