5

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)    
  })  
})
IRTFM
  • 258,963
  • 21
  • 364
  • 487
user32259
  • 1,113
  • 3
  • 13
  • 21
  • Please post the error messages. (For one thing function 'showOutput' is reported as not in 'shiny'. For another, 'rCharts' is not on CRAN.) – IRTFM Jul 01 '13 at 19:14
  • Once you rearrange the library calls and rerun the code there are no errors on a Mac with R 3.0.1, but hey... there is no call to `rPlot`, so how is anything suppose to happen??? – IRTFM Jul 01 '13 at 19:45
  • @DWin you can create plot without calling directly `rPlot`, the OP created a `Rickshaw` object just as in the examples http://ramnathv.github.io/rCharts/ – dickoa Jul 01 '13 at 20:00
  • Right, but I don't see anything similar to the `p4$print("chart6")` that would send a command to the server to do something. – IRTFM Jul 01 '13 at 20:03
  • Right, but I don't see anything similar to the p4$print("chart6") that would send a command to the server to do something. And when I execute the code on the example page, all I get is html code being output to the screen. I think there needs to be an installation sequence that is not being described in detail. – IRTFM Jul 01 '13 at 20:30
  • I'm sure there's a trick and may be you can try posting on the shiny mailing list (it's very active) – dickoa Jul 01 '13 at 21:04

2 Answers2

2

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")
  )
))
Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • It "works"? I think there might be some implementation or activation details that are apparent to you, but not to the rest of us. Nothing appears to change on either my console or in my browser. I really do like the demo that you offer http://ramnathv.github.io/rChartsParCoords/ but think there must be further steps to take – IRTFM Jul 02 '13 at 04:05
  • I am assuming you have installed the latest version of rCharts. Can you print out your `sessionInfo()`? – Ramnath Jul 02 '13 at 05:10
  • In my comment/answer. Considering that I installed it today per the instructions in your GitHub page, I think it should be the "latest". I was thinking it might be needed to be installed on a webserver. – IRTFM Jul 02 '13 at 06:50
  • thanks Ramnath. In my original code `showOutput` and `renderChart` did use the same plot id - sorry for the mistake in typing it up. The issue I was had was that I didn't include `rs$set(dom = "plot")` in the code. What does this do please? Cheers. – user32259 Jul 02 '13 at 09:01
  • also, are you able to get any interactivity when you run this app? I can't. For example, `hoverDetail` and `slider` don't seem to work. – user32259 Jul 02 '13 at 10:04
  • `rs$set(dcom = "plot")` tells rCharts to set the id of the plot to "plot". Future versions might dispense away with the need for this. The Rickshaw code has a bug while using with Shiny, due to which interactive features don't show up. I will try to fix it this week. – Ramnath Jul 02 '13 at 11:11
  • @Dwin. No. the above code should work out of the box if you have the latest rCharts and Shiny installed. Can you post a screenshot of what you get on your screen when you run the application? Might be better to move this discussion to github. – Ramnath Jul 02 '13 at 11:13
  • Cheers Ramnath. I'd like to thank you for your work so far on the fantastic `rCharts`. Regarding the bug, what's the best way to keep informed about this? Is there an `rCharts` group or something? – user32259 Jul 02 '13 at 12:26
  • I get no error. As I said, no visible response. No file in my working directory, either. `rPlot` on the other hand produces a new "webpage". Are you sure there isn't some sort of "new" call to the server that is not being issued? – IRTFM Jul 02 '13 at 14:18
  • Can you try `runGist("5789871afbd6602729ec")` ? and tell me what happens? Report on Github so that we can keep this SO thread clean. – Ramnath Jul 02 '13 at 14:24
  • @user32259 I would appreciate if you could file an issue on the github repo http://github.com/ramnathv/rCharts. I use it as a to-do list. – Ramnath Jul 02 '13 at 14:30
  • @Ramnath When I track down the code for the parallel coordiantes plot that you offer in you GitHub page at https://github.com/nachocab/clickme I get directions from application to start an HTTP server from within the directory holding the application. It runs beautifully with `demo_ractive("par_coords")` after executing `python -m SimpleHTTPServer`. Are you sure we don't need something like that. – IRTFM Jul 02 '13 at 17:02
  • @DWin `clickme` is a different package. No, rCharts works out of the box without the need for any further code. – Ramnath Jul 02 '13 at 17:43
1

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        
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • `rPlot` is a shorthand for plots using Polychart. I know it is not consistent with the rest of the naming conventions followed, but is a result of rCharts being initially designed only for use with Polychart. – Ramnath Jul 02 '13 at 02:13