jespermaag / gganatogram

Create anatograms using ggplot2
379 stars 52 forks source link

Using gganatogram within a loop of tabs #34

Closed brookebio closed 2 years ago

brookebio commented 2 years ago

I'm unable to print within a loop of tabs, and it seems like a limitation, as many other types of plots work using the print function.

Here's an example trying to output it using ggplotly. Is there a way to print like this through an "asis" chunk within gganatogram? Thank you.

knitr::opts_chunk$set(echo = TRUE)

library(gganatogram)
library(ggplot2)
library(plotly)

Tabs of Anatograms {.tabset}


list_to_output <- c("Tab 1","Tab 2","Tab 3")

for(i in list_to_output){

  cat("\n") 
  cat("### ", i, " {.tabset .tabset-pills}\n") # Create second level headings with the names.

  g <- gganatogram(data = hgMale_key,
            organism = "human", sex = "male",
            fill = "value",
            fillOutline = "#a6bddb")

  print("This is a test.")

  print(ggplotly(g),cat('\n'))
}
brookebio commented 2 years ago

okay - it's now working using the htmltools library and tagList(print(g))