I am outputting a table using shiny (with renderTable and tableOutput), is there a way to edit the format of the table and of the values within the table.
我正在使用refresh(具有renderTable和tableOutput)输出一个表,是否有一种方法可以编辑表的格式和表中的值。
Specifically I want to
具体我想
- Use comma as 1000 superator (i.e. change 1234567 to 1,234,567)
- 使用逗号作为1000 superator(即更改1234567至1,234,567)
- Put a £ sign before every value in one column
- 把£签署前一列的每个值
- Make the final row bold
- 将最后一行加粗
- Remove row names
- 删除行名称
So if you take the shiny reactivity e.g. as an example
所以如果你以闪亮的反应性为例
runExample('03_reactivity')
This outputs a table 'view', the server.R code for it is
这将输出一个表“view”,即服务器。R代表它
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
The ui.R code for it is
ui。R代表它
tableOutput("view")
In this example I would want 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
(With the header remaining bold and the bottom row also in bold, turns out * is equally difficult to get in the format I want ;))
(由于页眉仍然是粗体,而下一行也是粗体,所以*也同样难以以我想要的格式显示;)
1 个解决方案
#1
4
Hi I have added comments in my answer, hopefully this would help. Look in to Datatables here for more information how to customize your tables.
你好,我在我的回答中添加了评论,希望这能有所帮助。请查看这里的Datatables,了解如何定制表的更多信息。
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))
#1
4
Hi I have added comments in my answer, hopefully this would help. Look in to Datatables here for more information how to customize your tables.
你好,我在我的回答中添加了评论,希望这能有所帮助。请查看这里的Datatables,了解如何定制表的更多信息。
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))