I am trying to change the call parameters renderDataTablein Shiny to depend on the value of the input variable, in this case a checkbox.
The first checkbox successfully modifies the contents of the table by adding another column, if one is set. The second flag does not change the table settings. See the code below, I am downloading an updated version of datatables and other extensions, but this does not seem to have any effect here. The third checkbox also does not change the formatting of the records in the table, which I would ultimately want to do.
Any ideas?
library("ggplot2")
shinyServer(function(input, output, session) {
bold = reactive ({
bold = ''
bold = paste0(bold,'function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {')
bold = ifelse(input$checkbox3,paste0(bold),paste0(bold,'if (parseFloat(aData[0]) >= 0.1) { $("td:eq(0)", nRow).css("font-weight", "bold"); }'))
bold = paste0(bold,'}')
return(bold)
})
output$mytable = renderDataTable({
diamonds[,1:ifelse(input$checkbox1,6,5)]
}, options = list(fnRowCallback = I(bold()),aaSorting=list(list(2, ifelse(input$checkbox2,"asc","desc"))))
)
}
)
shinyUI({
pageWithSidebar(
h1('Diamonds DataTable with TableTools'),
tagList(
singleton(tags$head(tags$script(src='jquery.dataTables.min.js',type='text/javascript'))),
singleton(tags$head(tags$script(src='TableTools.min.js',type='text/javascript'))),
singleton(tags$head(tags$script(src='dataTables.colReorder.min.js',type='text/javascript'))),
singleton(tags$head(tags$script(src='colvis.js',type='text/javascript'))),
singleton(tags$head(tags$script(src='ZeroClipboard.min.js',type='text/javascript'))),
singleton(tags$head(tags$link(href='TableTools.min.css',rel='stylesheet',type='text/css'))),
singleton(tags$head(tags$link(href='ColVis.css',rel='stylesheet',type='text/css')))
, tags$head(
tags$style(HTML("
.cvclear{
text-align:right}")
)
)
),
tabPanel("foo",
checkboxInput("checkbox1", "add one more column", FALSE),
checkboxInput("checkbox2", "sort [desc] or [asc]", FALSE),
checkboxInput("checkbox3", "no bold", FALSE),
dataTableOutput("mytable")
)
)
})