htmlwidgets in Shiny?

I came across the following example of a package used to create very nice/interactive chord diagrams as htmlwidgets. They render beautifully in the 'viewer' tab of R Studio.

Can I put this into my shiny app? Is there something like renderPlot but for these types of widgets?

# Load package
# devtools::install_github("mattflor/chorddiag")
library(chorddiag)

# Create dummy data
m <- matrix(c(11975,  5871, 8916, 2868,
              1951, 10048, 2060, 6171,
              8010, 16145, 8090, 8045,
              1013,   990,  940, 6907),
            byrow = TRUE,
            nrow = 4, ncol = 4)

# A vector of 4 colors for 4 groups
haircolors <- c("black", "blonde", "brown", "red")
dimnames(m) <- list(have = haircolors,
                    prefer = haircolors)
groupColors <- c("#000000", "#FFDD89", "#957244", "#F26223")

# Build the chord diagram:
p <- chorddiag(m, groupColors = groupColors, groupnamePadding = 20)
p

# save the widget
# library(htmlwidgets)
# saveWidget(p, file=paste0( getwd(), "/HtmlWidget/chord_interactive.html"))

EDIT: I found out that I can insert this into the Shiny app just fine by making the graph before the ui even starts (right after loading libraries)....but I still need to do it for a 'reactive' situation. So, still looking for something analogous to renderPlot. Thanks!

renderChorddiag() and chorddiagOutput()?

https://datascience-enthusiast.com/R/Interactive_chord_diagrams_R.html

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.