dig*_*eep 6 r shiny-server rcharts
如何通过运行带有闪亮和rchart的多个图表来覆盖输出显示选项,以便输出结果为2x2矩阵类型的网格布局.
require(rCharts)
require(shiny)
require(data.table)
runApp(list(
ui = mainPanel( span="span6",
showOutput("chart2", "Highcharts"),
showOutput("chart3", "Highcharts"),
showOutput("chart4", "Highcharts")
),
server = function(input, output){
output$chart3 <- renderChart({
a <- hPlot(Pulse ~ Height, data = MASS::survey, type = "bubble", title = "Zoom demo", subtitle = "bubble chart", size = "Age", group = "Exer")
a$chart(zoomType = "xy")
a$chart(backgroundColor = NULL)
a$set(dom = 'chart3')
return(a)
})
output$chart2 <- renderChart({
survey <- as.data.table(MASS::survey)
freq <- survey[ , .N, by = c('Sex', 'Smoke')]
a <- hPlot(x = 'Smoke', y = 'N', data = freq, type = 'column', group = 'Sex')
a$chart(backgroundColor = NULL)
a$set(dom = 'chart2')
return(a)
})
output$chart4 <- renderChart({
survey <- as.data.table(MASS::survey)
freq <- survey[ , .N, by = c('Smoke')]
a <- hPlot(x = "Smoke", y = "N", data = freq, type = "pie")
a$plotOptions(pie = list(size = 150))
a$chart(backgroundColor = NULL)
a$set(dom = 'chart4')
return(a)
})
}
))
Run Code Online (Sandbox Code Playgroud)
将ui更改为:
ui = bootstrapPage(mainPanel(
div(class = "row",
div(showOutput("chart2", "Highcharts"), class = "span4"),
div(showOutput("chart3", "Highcharts"), class = "span4")
),
div(class = "row",
div(showOutput("chart4", "Highcharts"), class = "span4")
)
))
Run Code Online (Sandbox Code Playgroud)
添加bootstrapPage告诉有光泽使用bootstrap库.请查看http://getbootstrap.com/2.3.2/scaffolding.html以了解"脚手架".mainPanel有一个宽度选项,默认为8.这是bootstrap中的span8.上面的代码并不理想,但希望它是一个开始.
编辑:全屏
ui = bootstrapPage(mainPanel(width = 12,
div(class = "row",
div(showOutput("chart2", "Highcharts"), class = "span6"),
div(showOutput("chart3", "Highcharts"), class = "span6")
),
div(class = "row",
div(showOutput("chart4", "Highcharts"), class = "span6")
)
))
Run Code Online (Sandbox Code Playgroud)
请注意,mainPanel(...,width = width)只是div的一个便利函数,其宽度跨度.
结果截图:

| 归档时间: |
|
| 查看次数: |
5392 次 |
| 最近记录: |