'Change sparkline coloring in shiny DT table
Below is the code to develop sparkline in R. Wanted to check if we can change the color . I mean the negative values to be black and positive values to be red
library(shiny)
library(DT)
library(data.table)
library(sparkline)
## Create demo data sets
my_mtcars <- data.table(mtcars, keep.rownames = TRUE)
names(my_mtcars)[1] <- 'car_id'
set.seed(0)
data_for_sparklines <- data.table(car_id = rep(my_mtcars$car_id, 5),
category = 1:5,
value = c(runif(80),-runif(80)))
sparkline_html <- data_for_sparklines[, .(sparkbar = spk_chr(value, type = 'bar',barColor = "black")), by = 'car_id']
my_mtcars <- merge(my_mtcars, sparkline_html, by = 'car_id')
spk_add_deps(datatable(my_mtcars, escape = FALSE))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|