Reputation: 3441
I'm trying to embed an RChart into a shiny app. I'm specifically using the nPlot
function to create a type=scatterChart
NVD3 style plot. In the NVD3 website example below, there are two pieces of functionality I am interested in getting to work in my RCharts shiny app:
http://nvd3.org/ghpages/scatter.html
Does anyone know how to expand my code below to achieve these two pieces of functionality. Shiny server.r and ui.r scripts are included below.
## server.r
library(rCharts)
library(shiny)
x <- rnorm(100)
y <- rnorm(100)
dat <- as.data.frame(cbind(x,y))
shinyServer(function(input, output) {
output$myChart <- renderChart({
p1 <- nPlot(y ~ x, data = dat, type = "scatterChart")
p1$addParams(dom = 'myChart')
p1$params$height=400
p1$params$width=650
return(p1)
})
})
## ui.R
library(rCharts)
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("rCharts: Interactive Charts from R using NVD3.js"),
sidebarPanel(
wellPanel(
helpText( "Look at the pretty graph"
)
),
wellPanel(
helpText( "Look at the pretty graph"
)
),
wellPanel(
helpText( "Look at the pretty graph"
)
)
),
mainPanel(
div(class='wrapper',
tags$style(".Nvd3{ height: 400px;}"),
showOutput("myChart","Nvd3")
)
)
))
Thanks in advance for any advice you can provide.
Upvotes: 2
Views: 524
Reputation: 6579
This can be achieved using the following code:
p1$chart(
showDistX = TRUE,
showDistY = TRUE
)
return(p1)
Also, just as a note, while direct manipulation of p1$params
works, it might be safer to specify height
and width
in this way:
p1 <- nPlot(
y ~ x,
data = dat,
type = "scatterChart",
height = 400,
width = 650
)
Upvotes: 6