R shiny: change the output format of the table
I was outputting the table using brilliant (with renderTable and tableOutput) there is a way to edit the format of the table and values ββinside the table.
In particular, I want
- Use the comma as 1000 supers (i.e. change 1234567 to 1 234 567).
- Place a $ sign in front of each value in column one
- Make the final line bold.
- Remove row names
So if you take brilliant reactivity for example. as an example
runExample('03_reactivity')
This outputs the "table view", the .R server code for it is
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
Ui.R code for it
tableOutput("view")
In this example, I would like to output
area peri shape perm
Β£4,990 2,791.90 0.09 6.30
Β£7,002 3,892.60 0.15 6.30
Β£7,558 3,930.66 0.18 6.30
Β£7,352 3,869.32 0.12 6.30
Β£7,943 3,948.54 0.12 17.10
Β£7,979 4,010.15 0.17 17.10
Β£9,333 4,345.75 0.19 17.10
Β£8,209 4,344.75 0.16 17.10
Β£8,393 3,682.04 0.20 119.00
Β£6,425 3,098.65 0.16 119.00
(If the title stays bold and the bottom line is also bold, it turns out stackoverflow is also hard to get in the format I want;))
+3
source to share
1 answer
Hi I have added comments to my answer, I hope this helps. Refer to Datatables here for more information on how to set up tables.
rm(list = ls())
library(shiny)
library(scales)
# Sample Data
area <- seq(from=10,to=100, by=10)
peri <- seq(from=2710.1,to=2800.1, by=10)
shape <- seq(from=0.1,to=1, by=0.1)
perm <- seq(from=1,to=100, by=10)
my_data <- as.data.frame(cbind(area,peri,shape,perm))
ui = fluidPage(
sidebarLayout(
sidebarPanel(),
mainPanel(
tableOutput("view"),
#4 Make the final row bold using tags$style
tags$style(type="text/css", "#view tr:last-child {font-weight:bold;}")
),
)
)
server = function(input, output) {
output$view <- renderTable({
test <- my_data
#1 Comma Seperator as 1000: you can use the library(scales) and the comma function
test$peri<-comma(test$peri)
#2 Out the "Β£" sign before every value in column 1 (or any column): you can use paste0
test$area <- paste0("Β£",test$area)
test
#3 Remove row names : use inlcude.rownames=FALSE
},include.rownames=FALSE)
}
runApp(list(ui = ui, server = server))
+4
source to share