Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatable does not render in Shiny Dashboard

The datatable does not render in a Shinydashboard. It just renders a thin white strip for the box. Running only the datatable function in RStudio renders the datatable in the RStudio viewer. So what the correct way to render a DT datatable in a shiny app?

## app.R ##
library(shiny)
library(shinydashboard)
library(htmlwidgets)
library(DT)
library(xtable)
source('../ts01/db.R')

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      box(tableOutput("table1"))
    )
  )
)

server <- function(input, output) {
  output$table1 <- DT::renderDataTable({
    datatable(amount_data)
  })  
}

shinyApp(ui, server)
like image 984
Tim Child Avatar asked Jun 30 '15 04:06

Tim Child


2 Answers

You should try the following:

1) tableOutput

rm(list = ls())
library(shiny)
library(shinydashboard)
my_data <- head(mtcars)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      box(tableOutput("table1"))
    )
  )
)

server <- function(input, output) {
  output$table1 <- renderTable({
    my_data
  })  
}

shinyApp(ui, server)

2) dataTableOutput

rm(list = ls())
library(shiny)
library(DT)
library(shinydashboard)

my_data <- head(mtcars)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      box(DT::dataTableOutput("table1"))
    )
  )
)

server <- function(input, output) {
  output$table1 <- DT::renderDataTable({
    datatable(my_data)
  })  
}

shinyApp(ui, server)
like image 111
Pork Chop Avatar answered Oct 03 '22 16:10

Pork Chop


To make sure you use the right package to render your datatable use this in your ui instead:

DT::dataTableOutput('table1')
like image 36
JDH Avatar answered Oct 03 '22 17:10

JDH