如何在闪亮的 R 中为 gvisTable 提供标题

How to give title for gvisTable in shiny R

我是 shiny R 和 googleVis 的新手。我有一个名为 explore(...) 的方法,它根据作为参数传递的变量的数据类型在单独的 window 上创建一个 googleVis 图表(条形图、饼图等)。它还会检查用户是否选中了可视化选项(ui 上的复选框)。如果为真,它会渲染绘图以及 gVisTable,其中包含集中趋势和分散值。我能够通过使用 gVisMerge() 来做到这一点。但是,如果未选中 Visualize 复选框,则它只会在单独的页面上显示 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)
    })

这是一段来自 explore 方法的代码,它合并了绘图和 table。或者只是显示 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(...)是另一种生成条形图的方法,即

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 table 的 header as

来实现
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")