我开始使用R formattable包,但仍然面临一些问题,无法formattable()正确输出 pdf 文档。
第一个问题:在应用任何color_*仅适用于数字类的函数后,如何获得百分比格式的数字?
从在R环境中执行/运行的代码中查看下表。
a<-formattable(x=a,list(A=color_bar("orange", 0.2),B=color_bar("orange", 0.2),C=color_bar("orange", 0.2),D=color_bar("orange", 0.2),E=color_bar("orange", 0.2)))
Run Code Online (Sandbox Code Playgroud)
假设a作为csv我输入的文件read.csv()。
我想让“%”将数字粘贴在一起,同时将橙色条从 粘贴在一起formattable,但是如果我将 转换numeric为percentby percent()fromscale或 by paste(a,"%",sep="")formattable 将无法正常工作numeric,需要进行指责。
第二个问题:渲染为 pdf 时,未正确创建来自呈现的块的此类表。我尝试使用formattable(a,list...), byprint(a)和 by 的直接输出,print(xtable(a))但没有任何效果。任何提示?
我想知道是否可以将 mat 表格行放置在与表格组件不同的另一个组件中,这是一个示例:
<mat-table #table [dataSource]="dataSource" class="table" matSort>
<user-table-row> </user-table-row>
<ng-container matColumnDef="profile">
<mat-header-cell *matHeaderCellDef mat-sort-header class="header-cell"> Profile Type </mat-header-cell>
<mat-cell *matCellDef="let user" class="cell"> {{user.profile.type}} </mat-cell>
</ng-container>
<ng-container matColumnDef="status">
<mat-header-cell *matHeaderCellDef mat-sort-header class="header-cell"> Status </mat-header-cell>
<mat-cell *matCellDef="let user" class="cell"> {{user.profile.status}} </mat-cell>
</ng-container>
<!-- Header and Row Declarations -->
<mat-header-row *matHeaderRowDef="['createdAt', 'email', 'profile', 'status', 'isApproved', 'actions']" class="header-row"></mat-header-row>
<mat-row *matRowDef="let row; columns: ['createdAt', 'email', 'profile', 'status', 'isApproved', 'actions']" class="row"></mat-row>
</mat-table>
Run Code Online (Sandbox Code Playgroud)
我如何制作这样的东西:
<mat-table #table [dataSource]="dataSource" class="table" matSort>
<user-table-row> </user-table-row>
</mat-table>
Run Code Online (Sandbox Code Playgroud)
可能吗,有人以前做过吗?
我对使用formattableR 包中的工具感兴趣,但我只想在表中显示有变化的地方。也就是说,我想要kableExtra通过collapse_rows()函数在包中提供的分层行标签。
例如,使用kable()and kableExtra,我可以这样做:
library(dplyr)
library(knitr)
library(kableExtra)
iris %>%
group_by(Species) %>%
slice(1:2) %>%
select(Species, everything()) %>%
kable() %>%
collapse_rows(1, valign="top")
Run Code Online (Sandbox Code Playgroud)
产生这个:
但是,我想使用formattable包和函数来执行此操作,以便我可以在输出期间在特定列上运行任意函数。具体来说,我想添加“迷你图”作为新列。我可以使用knitrand做到这一点formattble,但collapse_rows据我所知,我失去了。
有什么办法可以折叠行formattable吗?
我有一张表在一个闪亮的应用程序中显示.我想根据值格式化表格并相应地对其进行着色.我已经看到了格式化区域着色,其中基于它定义断点的值的范围,然后生成应用于表格的颜色渐变.我想要做的是允许用户填充最小值和最大值,并根据它,表中的值将被着色.因此,如果值的范围为1-20,并且如果用户输入为5和15,则低于5且高于15的值不应对其应用任何颜色渐变.下面是我目前正在使用格式化区域格式的代码.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow( column(
width = 3, textInput("text1", label = h5("Min"), value = "Enter min")),
column(
width = 3, textInput("text2", label = h5("Max"), value = "Enter max"))),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda …Run Code Online (Sandbox Code Playgroud) 这是我正在使用的格式化对象的最小示例:
library(formattable)
formattable(mtcars,
align = "c",
list(~ formatter("span",
style = x ~ formattable::style(display = "block",
"border-radius" = "2px",
"padding" = "5px",
"text-align" = "center"))))
Run Code Online (Sandbox Code Playgroud)
如何修改它以加粗行名称?
示例数据(从formattablegithub docs 修改):
df <- data.frame(
id = 1:10,
name = c("Bob", "Ashley", "James", "David", "Jenny",
"Hans", "Leo", "John", "Emily", "Lee"),
age = c(48, 47, 40, 28, 29, 29, 27, 27, 31, 30),
test1_score = c(18.9, 19.5, 19.6, 12.9, 11.1, 7.3, 4.3, 3.9, 2.5, 1.6),
test2_score = c(9.1, 9.1, 9.2, 11.1, 13.9, 14.5, 19.2, 19.3, 19.1, 18.8),
stringsAsFactors = FALSE)
Run Code Online (Sandbox Code Playgroud)
您可以使用这样的额外颜色格式制作漂亮的表格:
library(formattable)
formattable(df, list(
age = color_tile("white", "orange"),
test1_score = color_bar("pink", 0.2),
test2_score = color_bar("pink", 0.2)
))
Run Code Online (Sandbox Code Playgroud)
看起来像这样: …
这些扩展 Buttons非常适合闪亮的应用程序,从library(DT). 但是它导出数据时不进行格式化。有没有办法以格式(例如百分比或货币)导出数据?类似的问题尚未解决。
可重现的代码
library(DT)
data.frame(a = c(1,2),
b = c(2,3)) %>%
datatable(extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')) )%>%
formatPercentage('a') %>%
formatCurrency('b')
Run Code Online (Sandbox Code Playgroud) Formattable 有一些简单的格式化表格选项,例如:
library(shiny)
library(DT)
library(formattable)
df <- formattable(iris, lapply(1:4, function(col){
area(col = col) ~ color_tile("red", "green")
Run Code Online (Sandbox Code Playgroud)
这以后可以coverted到DT数据表
df <- as.datatable(df)
Run Code Online (Sandbox Code Playgroud)
对我来说,在RStudion的Viewer中查看是完美的.但是,我想以某种方式将其部署为Shiny应用程序.完整代码:
library(DT)
library(shiny)
ui <- fluidPage(
DT::dataTableOutput("table1"))
server <- function(input, output){
df <- formattable(iris, lapply(1:4, function(col){
area(col = col) ~ color_tile("red", "green")
}))
df <- as.datatable(df)
output$table1 <- DT::renderDataTable(DT::datatable(df))
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
这不起作用,有什么工作吗?我喜欢条件格式formattable,但也想使用一些DT提供的选项,例如过滤,搜索,colvis等.
要将它部署为formattable有一个线程:
我正在尝试将 formattable 与物种的某些值一起使用,因此,列名称为斜体非常重要;我尝试过该formatter()函数,但它只作用于值,即使我使用"th"节点而不是"span"
library(formattable)
make_italic <- formatter("span",
style = "font-style:italic")
formattable(mtcars, list(mpg = make_italic, qsec = make_italic))
Run Code Online (Sandbox Code Playgroud)
在 mtcars 中,如何将名称(mpg、cyl、disp...)更改为斜体?
我如何强制使用Powershell
Format-Table -auto
Run Code Online (Sandbox Code Playgroud)
将返回的对象数组写入控制台时的默认格式?谢谢
formattable ×10
r ×8
shiny ×4
dt ×3
angular ×1
datatables ×1
formatting ×1
html ×1
knitr ×1
powershell ×1
r-markdown ×1
xmltable ×1