I have a reactable
which contains react_sparklines
from the {reactablefmtr} package which in turn is based on the {dataui} package (at least the sparklines).
I want to set the y axis in each row to a different value and it is not working (see below for what is and what is not working).
Is there a way to set the y axis in each row to a different value? I would welcome approaches that either ...
make it work with the existing* (see Update below)react_sparklines
function or- change the underlying function to make it work or
- rely on a different package (not {dataui}) to create the sparklines (however they should be equally nice looking).
Update: The maintainer of {reactablefmtr} told me on Twitter that react_sparklines
does not allow different y axis limits across rows in the current version.
I still would be interested in options 2. & 3. above.
library(dplyr)
library(reactable)
library(reactablefmtr)
library(dataui) # this is needed for {reactablefmtr}'s sparklines
# the input data
set.seed(123)
mydat <- tibble(id = c("A", "B", "C"),
data = list(sample(c(1:20), 20),
sample(seq(5, 100, by = 5), 20),
sample(seq(2.5, 50, by = 2.5), 20)
)
)
# (1) y axis range not specified
# Each sparkline has its own limit on the y axis equalling the max of each data set
# works
reactable(mydat,
columns = list(
data = colDef(
cell = react_sparkline(
mydat,
height = 80,
show_area = TRUE,
tooltip_type = 2
)
)
)
)
)
# (2) y axis specified to 100
# Each sparkline has the same max limit on the y axis: 100
# works
reactable(mydat,
columns = list(
data = colDef(
cell = react_sparkline(
mydat,
height = 80,
show_area = TRUE,
max_value = 100,
tooltip_type = 2
)
)
)
)
)
# (3) y axis specified to 50,100,50 for each graph respectively
# Each sparkline should have its own limit set to: 50, 100, 50 respectively
# does not work!! y axis limit is same as one (1) the maximum of each data set
reactable(mydat,
columns = list(
data = colDef(
cell = react_sparkline(
mydat,
height = 80,
show_area = TRUE,
max_value = c(50, 100, 50),
tooltip_type = 2
)
)
)
)
)
I found a way to do it by changing the underlying function
react_sparkline
. At the end of the post I show the full functionmySparkline
and highlight in the comments which part I added.Now two new options are possible:
First, we can add a vector of length > 1 containing the maximum value for each data set:
Second, we can use a function instead which is applied to the maximum value of each data set:
Below is the new function
mySparkline
. Look for the comments saying## new code
.