如何通过运行带有闪亮和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)
})
}
))
答案 0 :(得分:6)
将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")
)
))
添加bootstrapPage
告诉有光泽使用引导程序库。请看http://getbootstrap.com/2.3.2/scaffolding.html以了解&#34;脚手架&#34;。 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")
)
))
请注意,mainPanel(...,width = width)只是div的一个便利函数,其宽度为。
结果的屏幕截图:
答案 1 :(得分:1)
R Shiny原生的另一种解决方案(没有HTML的外部知识)是使用列的想法。
$result = Yii::app()->db->createCommand()->select('a.parameter_name, a.unit, b.result, b.normal_value')
->from('parameter a')
->join('test b', 'a.parameter_id = b.parameter_id')
->where('b.noRM='.$_POST['no_rm'])
->queryAll();