r - 如何设置表格格式以包含条形周围的轮廓

标签 r shiny dt

我正在尝试在 R Shiny 中格式化表格,条形图显示得很好,只是行与行之间没有任何空白(或轮廓)。我的代码如下:

formatStyle('score', background = styleColorBar(real$score, 
'lightblue'),
 backgroundSize = '100% 50%',
 backgoundRepeat = 'no-repeat',
backgroundPosition = 'center')

enter image description here

我正在寻找的是这样的:

enter image description here

最佳答案

这是一个可能的解决方案:

---
title: "Untitled"
author: "Author X. Person"
date: "October 11, 2018"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r tabsets, echo=FALSE, message=FALSE, warning=FALSE}
library(DT)
library(data.table)

d = data.table(x = 1:10,time = as.POSIXct('2018-10-11 12:00:00.123'))
d$score <- seq(1,10,1)

datatable(d, options=list(
 initComplete = JS("
    function(settings, json) {
      $(this.api().table().td()).css({
        'border-collapse': 'collapse',
        'border-bottom-width': '4px',   
        'background-color': '#000',
        'color': '#eee'
      });
    }"),
        pageLength = 10,
        lengthMenu = c(2, 12, 18),
        searching= FALSE)) %>% 
formatStyle('score', background = styleColorBar(d$score, 'lightblue'),
        backgroundSize = '100% 50%',
        backgroundRepeat = 'no-repeat',
        backgroundPosition = 'center')
```

结果如下:

enter image description here

关于r - 如何设置表格格式以包含条形周围的轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52727229/

相关文章:

R 绘图 : Using italics and a variable in a title

r - 比较两个矩阵,保持一个矩阵中的值在另一个矩阵中为 TRUE

r - 绑定(bind)许多数据框,添加一个带有其 id 的列

r - 响应式(Reactive)值(value)和响应式(Reactive)表达有什么区别?

r - Shiny 的 R renderText 粘贴新行并加粗

r - Shiny 的数据表 : popup data about selected row in a new window

数据表:隐藏“显示条目”下拉列表,但保留“搜索”框

r - googleVis:多级排序功能 gvisTable sortColumn?

r - pickerInput 默认选择所有选项

删除最终用户对列进行排序的能力