Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
like image 596
Akshit Avatar asked Oct 27 '15 08:10

Akshit


People also ask

What package is Formattable in R?

The formattable package is used to transform vectors and data frames into more readable and impactful tabular formats. I'm going to walk you through a step-by-step example of using the formattable R package to make your data frame more presentable for data storytelling.

How do I show a shiny table in R?

If you want to show a table, just use tableOutput and renderTable functions.


1 Answers

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)
like image 177
MySchizoBuddy Avatar answered Sep 19 '22 06:09

MySchizoBuddy