Create a dynamic table with DT::datatable in flexdashboard

Viewed 1164

I have a follow RMarkdown file:

---
title: "Table"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
---

```{r}
library(tidyverse)

df_1 <- data.frame(
  x = replicate(
  n = 6, expr = runif(n = 30, min = 20, max = 100)
  ), 
  y = as.factor(x = sample(x = 1:3, size = 30, replace = TRUE)), 
  z = rep(letters[1:10], each = 3)
)
```

```{r}
library(flexdashboard)
library(shiny)
library(DT)
```

DataTable
====================================

###
```{r}
datatable(data = df_1, 
          options = list(pageLength = 10, lengthMenu = c(5, 10, 15, 20, 25, 30), 
                         autoWidth = TRUE, columnDefs = list(list(className = 'dt-center', 
targets = "_all"))), 
              filter = "top", rownames = FALSE, caption = "Customer sum", selection = 
'single') %>% 
  formatRound(columns = 1:6, digits = 1) %>% 
  formatCurrency(columns = 1:6, currency = "$ ")
```

How to sum columns from x.1 to x.6 (for each column), always updating with the filters of y and z?

  • I want to create a total for each column, even applying the filters. Like this:

enter image description here

I know that there are solutions with shiny, only. But I need to apply this to flexdashboard.

Thanks.

0 Answers
Related