3

When I run rCharts with Shiny only the top of the plot shows in my local console. I have absolutely no idea why this is, I'm running the latest dev versions of both rCharts and Shiny. Any help would be greatly appreciated!

The two files below should fully reproduce the problem. Thanks in advance, Sebastian

## server.R
require(rCharts)
library(RCurl)
options(RCHART_WIDTH = 800)
shinyServer(function(input, output) {
output$myChart <- renderChart({
x <- getURL("https://raw.github.com/sebastianbarfort/vaa/master/vaa_.csv")
df___ <- read.csv(text = x)
p2 <- nPlot(Economy ~ Immigration, group = 'X.1', data = df___, 
               type = 'scatterChart')
p2$chart(color = c('red', 'blue', 'green',"yellow","yellow","yellow","yellow","yellow"))
p2$set(dom = "myChart")
return(p2)
})
})


##ui.R
require(rCharts) 
shinyUI(pageWithSidebar(
headerPanel("xxx"),
sidebarPanel(
selectInput(inputId = "x",
            label = "Choose X",
            choices = c("CL", "Economy", "Education", "Envrionment",    "EU",
                        "FP",   "Health",   "Immigration"),
            selected = "Economy"),
selectInput(inputId = "y",
            label = "Choose Y",
            choices = c("CL", "Economy", "Education", "Envrionment",  "EU",
                        "FP",   "Health",   "Immigration"),                
            selected = "Immigration")
),
mainPanel(
showOutput("myChart","Nvd3")
)
))

In case loading the csv from Github fails (which it shouldn't if you load RCurl), here is a direct link to the data on Github: https://github.com/sebastianbarfort/vaa/blob/master/vaa_.csv

  • Please try to run your example on a different computer; I gave up correcting it. The first line df__ is a leftover and gives an error. The next df__ has as security problem on computers without you certificate; it might work with some curl-stuff, but not in plain R. – Dieter Menne Jul 14 '13 at 17:05
  • the code should work now, as long as RCurl is loaded. In case it doesn't, I've included a direct link to the csv on Github. – Sebastian Barfort Jul 14 '13 at 18:19

1 Answers1

7

Here is a quick fix. Modify your mainPanel line to the following. The chart div needs to have a minimum height set for it to display correctly. I had pushed a fix to correct this, but it still has a minor bug. I will be pushing a more comprehensive fix to rCharts this week, which should take care of this issue, and not warrant you to add the tags$style line.

mainPanel(
  div(class='wrapper',
    tags$style(".Nvd3{ height: 400px;}"),
    showOutput("myChart","Nvd3")
  )
)

NOTE. While using with Shiny, it is preferred to use the non-formula interface, since Shiny inputs are interpreted as strings. Future versions might relax this requirement. So, for example, the line initializing the plot would be

p2 <- nPlot(x = input$x, y = input$y, group = 'X.1', 
  data = df___, type = 'scatterChart')

EDIT. If you have the dev version of rCharts installed (the dev branch), you can add elementary controls like what you have in your application, without needing Shiny. Here is how you would do it. This feature is still experimental and the API will change as I continue to simplify the code base, so use with caution.

require(rCharts)
require(RCurl)
x <- getURL("https://raw.github.com/sebastianbarfort/vaa/master/vaa_.csv")
df___ <- read.csv(text = x)
p2 <- nPlot(Economy ~ Immigration, 
  group = 'X.1', 
  data = df___, 
  type = 'scatterChart'
)
p2$chart(color = c('red', 'blue', 'green',"yellow","yellow","yellow",
  "yellow","yellow")
)
p2$addControls("x", value = "Immigration", values = names(df___)[-c(1:2)])
p2$addControls("y", value = "Economy", values = names(df___)[-c(1:2)])
Ramnath
  • 54,439
  • 16
  • 125
  • 152
  • Hi @Ramnath, thanks for your help. The latter works perfect, but I would prefer to use the Shiny option until you've settled on an API. In the Shiny version, when I change p2 <- nPlot(Economy ~ Immigration, group = 'X.1', data = df___, type = 'scatterChart') to p2 <- nPlot(input$x ~ input$y, group = 'X.1', data = df___, type = 'scatterChart') the points are all shown in the top left corner. Is there something wrong with my code? Thanks for all your work on rCharts and Slidify, they're both fantastic! Best, Sebastian – Sebastian Barfort Jul 14 '13 at 21:16
  • Nice, works for me under Chrome; the point effects are unintrusively helpful. The usual "not under Firefox locally on Windows 7, 64 bit" applies, however. And not under IE; which is interesting, because I always thought it was a shiny problem under IE. – Dieter Menne Jul 15 '13 at 06:39
  • Thanks @DieterMenne I hope to tackle the Firefox/IE issue once I get things stable under Chrome. I appreciate your help and effort in checking things out! – Ramnath Jul 15 '13 at 15:43
  • Hi Ramnath, thanks for the note. I have the same Firefox problem as Dieter, but everything works in Chrome. The plot responds much faster when using $addControls than when running in Shiny, but both get the job done. – Sebastian Barfort Jul 16 '13 at 07:35
  • Great. If it works, can you accept the answer so that the question can be closed? – Ramnath Jul 16 '13 at 21:06