[英]How to give title for gvisTable in shiny R
我是闪亮的R和googleVis的新手。 我有一个称为explore(...)的方法,该方法根据作为参数传递的变量的数据类型在单独的窗口上创建googleVis图表(条形图,饼图等)。 它还检查用户是否已选中“可视化”选项(ui上的checkBox)。 如果为true,则将绘制图与gVisTable
一起呈现,该gVisTable
包含中心趋势和离散值。 我能够通过使用gVisMerge()
做到这一点。 但是,如果未选中“可视化”复选框,则仅在单独的页面上显示gVisTable
。 在后一种情况下,我需要给gVisTable
一个标题。
这就是单击按钮时发生的情况。 调用名为explore()
方法来生成图。
observeEvent(input$exploreButton, {
print(input$variableInput)
options <- list()
options$variableName <- input$variableInput
options$visualize <- input$visualizeCheckBox
options$centralTendency <- input$centralTendencyCheckBox
options$dispersion <- input$measureDispersionCheckBox
explore(dataset[, input$variableInput], options)
})
这是来自explorer方法的一段代码,该代码合并了绘图和表格。 或者只是显示gvisTable。
informationTable <- gvisTable(as.data.frame.matrix(valuesTable), options=list(height=300, width=200))
if(options$visualize)
{
barChart <- getSimpleBarChart(table(x), paste("Bar Chart for ", options$variableName), "bottom", 1500, 600)
plot(gvisMerge(barChart, informationTable, horizontal=FALSE))
}
else {
plot(informationTable)
}
这里的getSimpleBarChart(...)
是编写生成BarChart的另一种方法,即
getSimpleBarChart <- function(data, title, legend_location='bottom', width=400, height=400) {
options <- list(title=title, legend=legend_location, tooltip="{isHtml:'True'}", bar="{groupWidth:'90%'}", width=width, height=height)
g <- gvisBarChart(as.data.frame(data), options=options)
g
}
有什么方法可以像在其余googleVis图表中一样为gVisTable
赋予标题? 请帮忙...
这可以通过首先获取gvis表的标头为
myGvisTable$html$header
因此它是html,可以使用paste()方法轻松将标题附加到它
informationTable$html$header <- paste("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\ ......", "<h2>Your title of table</h2>", "</head>\n<body>\n")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.