How to use R package "formattable" in shiny dashboard?

Akshit picture Akshit · Oct 27, 2015 · Viewed 11k times · Source

Below is the code I have written. I am not able to use formattable in my shiny. formattable helps in formatting the tables and improves the visualization also.

library("shinydashboard")
library("shiny")
library("formattable")

body <- dashboardBody(
  fluidRow(
    column(width = 12,
           box(tableOutput(formattable(test.table, list())))
           )
    )
  )

ui <- dashboardPage(
  dashboardHeader(title = "Column layout"),
  dashboardSidebar(),
  body
)

server <- function(input, output) {

  test.table <- data.frame(lapply(1:8, function(x) {1:10}))

    output$table <- renderTable({test.table})
}
shinyApp(ui = ui, server = server)

Answer

MySchizoBuddy picture MySchizoBuddy · Jan 15, 2016

you have to use renderFormattable, formattableOutput and formattable, all three for it to work

library("shinydashboard")
library("shiny")
library("formattable")

body <- dashboardBody(
 fluidRow(
   column(width = 12,
        box(formattableOutput("table"))
   )
 )
)

ui <- dashboardPage(
    dashboardHeader(title = "Column layout"),
    dashboardSidebar(),
    body
 )

 server <- function(input, output) {

    test.table <- data.frame(lapply(1:8, function(x) {1:10}))

    output$table <- renderFormattable({formattable(test.table, list())})
}
shinyApp(ui = ui, server = server)