Akshit Akshit - 1 month ago 40
R Question

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

Below is the code I have written. I am not able to use

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

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)