Savvas Kourtis
Savvas Kourtis

Reputation: 121

Nested dataframes interactive R markdown

I am trying to create a report following some analysis but it results in too many tables related to each table in the 'master output table'. So instead I've been trying to nest each table in its appropriate row creating a nested df-column in a df.

This is an example of what I'm trying to create and in the Rstudio viewer it looks exactly how I want. The user can click on each nested df to expand it.

[![enter image description here][1]][1]

I've tried tibbles, reactable, DT, Kable and data.table but they all seem to be presenting something different (either not expandable information e.g. < df > , or just printing everything which creates an unusable report)

My next option is producing a shiny app but they output cannot be sent to user so I'd rather avoid that.


title: "test"

output: html_document

knitr::opts_chunk$set(echo = TRUE)
library("tidyverse")
library("rlist")
library(reactable)
library(tibble)

The json file "br08001.json" comes from here https://www.genome.jp/kegg-bin/get_htext?br08001+C00186 - 'Download json'


KEGG_compounds <- jsonlite::fromJSON('br08001.json', flatten = TRUE)
df <- KEGG_compounds[[2]]
tibble::as_tibble(df)

_____________________ Improvements as suggested by @Daniel Jachetta____________

---
title: "Test"
author: "..."
date:  "`r Sys.Date()`" 
output: 
  html_document
---
```{r}

KEGG_compounds <- jsonlite::fromJSON('C:/Users/skourtis/Downloads/br08001.json', flatten = TRUE)[[2]]
DT::datatable(KEGG_compounds)

```

<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName"> Organic Acids </button>  
<div id="BlockName" class="collapse">


```{r}
DT::datatable(KEGG_compounds[[2]][[1]])

```

</div>

<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName1"> Lipids </button>  
<div id="BlockName1" class="collapse"> 




```{r}
DT::datatable(KEGG_compounds[[2]][[2]])
```

</div>

<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName2"> Carbohydrates </button>  
    <div id="BlockName2" class="collapse">  


```{r}
DT::datatable(KEGG_compounds[[2]][[3]])
```

</div>

Upvotes: 1

Views: 547

Answers (1)

Daniel_j_iii
Daniel_j_iii

Reputation: 3252

This doesn't really have the graphical aspect, but this gives you buttons for each dataset name. Can you help me access the tibbles inside your tibbles and I can modify my rough draft answer.

---
title: "Test"
author: "..."
date:  "`r Sys.Date()`" 
output: 
  html_document
---
<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName"> iris </button>  
<div id="BlockName" class="collapse">  


```{r}
print(iris)

```

</div>

<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName1"> Cars </button>  
<div id="BlockName1" class="collapse">  


```{r}
print(mtcars)
```

</div>

Upvotes: 1

Related Questions