由于您尚未提供构成该表的HTML代码,因此我亲自复制了该表:
<table border = "5">
<thead>
<tr>
<th colspan="2" height = "100" width = "800">TABLE TITLE</th>
</tr>
</thead>
<tbody>
<tr>
<style>
tr:nth-child(1) { border: solid thick; }
</style>
<td align = "center"><strong>Column A</strong></td>
<td align = "center"><strong>Column B</strong></td>
</tr>
<tr style="border: solid thick">
<td align = "center"><strong>Data 1</strong></td>
<td align = "center"><strong>Data 2</strong></td>
</tbody>
</table>
现在,您几乎可以按照HTML的流程将其直接转换为R代码,而无需将样式标签放置在一个函数调用中。
tags$head(tags$table(border = 5,
tags$thead(
tags$tr(
tags$th(colspan = 2, height = 100, width = 800,
align = "center", "TABLE TITLE")
)
),
tags$tbody(
tags$tr(
tags$td(align = "center", strong("Column A")),
tags$td(align = "center", strong("Column B"))
),
tags$tr(
tags$td(align = "center", "Data 1"),
tags$td(align = "center", "Data 2")
)
)
)
)
其中<
对应于(
,同样</
对应于)
。如果在关闭前一个标签之前打开了新标签,即在open内<
放置一个新标签。最终的输出还是HTML代码,因此请继续尝试直到输出与您拥有的HTML匹配。tags$...
tags$...
但是,由于它具有其他样式,因此需要花费相当多的CSS才能进入决赛桌。我们使用一次tags$head(tags$style())
调用将所有CSS代码放在一个地方以提高可读性。
tags$head(tags$style(
'thead {
display: table-header-group;
vertical-align: middle;
border-color: inherit;
}
tr:nth-child(1) {
border: solid thick;
}
tr:nth-child(2) {
border: solid thick;
}
th {
text-align: center
;
}
td, th {
outline: none;
}
table {
display: table;
border-collapse: separate;
white-space: normal;
line-height: normal;
font-family: times-new-roman;
font-weight: normal;
font-size: medium;
font-style: normal;
color: -internal-quirk-inherit;
text-align: start;
border-spacing: 2px;
border-color: grey;
font-variant: normal;
}
td {
display: table-cell;
vertical-align: inherit;
}
tr {
display: table-row;
vertical-align: inherit;
}
'
))
如果您具有要复制的源代码,则可以在浏览器中使用inspect元素来获取CSS代码。如果没有,您将需要一些外部资源(例如Stackoverflow,WS3学校,JSfiddle等)来获得最终的Web应用程序。
将所有内容整合到一个闪亮的应用程序中:
library(shiny)
ui <- fluidPage(
tags$head(tags$style(
'thead {
display: table-header-group;
vertical-align: middle;
border-color: inherit;
}
tr:nth-child(1) {
border: solid thick;
}
tr:nth-child(2) {
border: solid thick;
}
th {
text-align: center
;
}
td, th {
outline: none;
}
table {
display: table;
border-collapse: separate;
white-space: normal;
line-height: normal;
font-family: times-new-roman;
font-weight: normal;
font-size: medium;
font-style: normal;
color: -internal-quirk-inherit;
text-align: start;
border-spacing: 2px;
border-color: grey;
font-variant: normal;
}
td {
display: table-cell;
vertical-align: inherit;
}
tr {
display: table-row;
vertical-align: inherit;
}
'
)),
tags$head(tags$table(border = 5,
tags$thead(
tags$tr(
tags$th(colspan = 2, height = 100, width = 800,
align = "center", "TABLE TITLE")
)
),
tags$tbody(
tags$tr(
tags$td(align = "center", strong("Column A")),
tags$td(align = "center", strong("Column B"))
),
tags$tr(
tags$td(align = "center", "Data 1"),
tags$td(align = "center", "Data 2")
)
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
这使:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句