作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 RChart 嵌入到 Shiny 的应用程序中。我专门使用 nPlot
函数来创建 type=scatterChart
NVD3 样式图。在下面的 NVD3 网站示例中,我有兴趣在我的 RCharts Shiny 应用程序中使用两个功能:
http://nvd3.org/ghpages/scatter.html
有谁知道如何扩展我下面的代码来实现这两个功能。下面包含 Shiny 的 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")
)
)
))
提前感谢您提供的任何建议。
最佳答案
这可以使用以下代码实现:
p1$chart(
showDistX = TRUE,
showDistY = TRUE
)
return(p1)
此外,请注意,虽然直接操作 p1$params
有效,但在中指定 height
和 width
可能更安全这样:
p1 <- nPlot(
y ~ x,
data = dat,
type = "scatterChart",
height = 400,
width = 650
)
关于RCharts 散点图增强功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19085351/
我是一名优秀的程序员,十分优秀!