missy morrow
missy morrow

Reputation: 337

renderDataTable in Shiny not rendering output correctly

I am executing a very minimal renderDataTable example posted on the DT github page below http://rstudio.github.io/DT/shiny.html

library(shiny)
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      iris, options = list(lengthChange = FALSE)
    )
  }
)

However, the output I am seeing after executing this code is garbage, column names listed in a single line without space.

enter image description here

I tried this after uninstalling my DT packages and reinstalling again

devtools::install_github('rstudio/DT')

Nothing changed, still the same results. I don't understand why DT::renderDataTable() is not working. Any suggestions is greatly appreciated.?

-------------Update----------------

I started noticing this issue after I started building some shinyapps using Flexdashboard. Before installing Flexdashboard package everything was working as usual and there was no problem, after installing Flexdashboard i noticed this issue with datatables while using renderDataTable function

Upvotes: 4

Views: 2525

Answers (1)

missy morrow
missy morrow

Reputation: 337

This issue is about not being able to see the contents of a datatables while using the renderdatatable function.

This happens if the users using renderdatatable function in their regular shiny app switch from shiny to flexdashboard try to run flexdashboard apps that use renderdatatable function and switch back to shiny.

The flexdashboard library 1) will not render the datatables through the renderdatatable function, at least as of today it did not 2) Further the flexdashboard library corrupts some of the functionalities within the datatables package and when the user tries to switch back to regular Shiny from flexdashboard , the user may find that the renderdatatable function that worked earlier might not render the datatables accurately.

According to JJ Allaire, the solution is to add these two lines in your shiny

 options(DT.fillContainer = FALSE) 
 options(DT.autoHideNavigation = FALSE) 

This will clean up all the hooks flexdashboard creates within the datatable package and datatable should render normally like before in Shiny.

Upvotes: 3

Related Questions