I am having a hard time to render my footer column in a reactable. I want to use JS here to access the client-side filtered state, and since iam not too familiar with JS i am stuck. What i want is: to use the summarized footer values from two columns to create a summarized footer value for a third column. See example below.
library(shiny)
library(tidyverse)
data = tibble(article =c("a", "b", "c"), sales = c(12,34,16), margin = c(6,20,9)) %>%
mutate(profit = round(margin / sales * 100, digits = 2))
ui = fluidPage(
div(style = "margin-top: 50px; display: flex; justify-content: center;",
reactableOutput(outputId = "table"))
)
server = function(input, output, session){
output$table = renderReactable({
reactable(
data = data,
columns = list(
article = colDef(
footer = "..."),
sales = colDef(
format = colFormat(suffix = "€"),
footer = JS("function(colInfo) {
var total = 0
colInfo.data.forEach(function(row) {
total += row[colInfo.column.id]
})
return total.toFixed(2) + '€'}")),
margin = colDef(
format = colFormat(suffix = "€"),
footer = JS("function(colInfo) {
var total = 0
colInfo.data.forEach(function(row) {
total += row[colInfo.column.id]
})
return total.toFixed(2) + '€'}")),
profit = colDef(
format = colFormat(suffix = "%"),
footer = "35/62*100"
)
))
})
}
shinyApp(ui, server)