I am newbie to shiny R and googleVis. I have a method called explore(...) which creates a googleVis chart (either Bar Chart, Pie, etc.) on a separate window depending on the datatype of the variable passed as parameter. It also checks if the user has checked the option of Visualize (checkBox on ui). If it is true, it renders the plot along with a gVisTable
that holds central tendency and dispersion values. I was able to do this by using gVisMerge()
. But if Visualize checkBox is not checked, it only displays gVisTable
on a separate page. In the latter case I need to give a title to gVisTable
.
This is what happens on button click. A method named explore()
is called to generate plot.
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)
})
And this is a piece of code from explore method that merges the plot and the table. Or simply displays the 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)
}
Here getSimpleBarChart(...)
is another method written to generate BarChart i.e.
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
}
Is there any way to give title to gVisTable
like we do in rest of the googleVis charts? Please help...
This can be achieved by first fetching the header of the gvis table as
myGvisTable$html$header
It is html therefore, heading can be appended to it easily using the paste() method as
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")