我正在尝试将一个RChart嵌入到一个闪亮的应用程序中。我特别使用nPlot函数来创建一个type=scatterChart NVD3样式图。在下面的NVD3网站示例中,有两项功能我有兴趣在我的RCharts闪亮应用程序中使用:
http://nvd3.org/ghpages/scatter.html
有人知道如何展开下面的代码来实现这两项功能吗?下面包含了闪亮的server.r和ui.r脚本。
## 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")
)
)
))谢谢你能提供的任何建议。
发布于 2013-09-30 02:41:27
这可以使用以下代码来实现:
p1$chart(
showDistX = TRUE,
showDistY = TRUE
)
return(p1)另外,请注意,虽然p1$params的直接操作是有效的,但以这种方式指定height和width可能更安全:
p1 <- nPlot(
y ~ x,
data = dat,
type = "scatterChart",
height = 400,
width = 650
)https://stackoverflow.com/questions/19085351
复制相似问题