Reputation: 117
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
Upvotes: 3
Views: 1929
Reputation: 55735
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)])
Upvotes: 7