Streamgraph - streamgraph_html returned an object of class `list` instead of a `shiny.tag` error

Viewed 91

For this week's TidyTuesday challenge, I am trying to plot a stream graph of the top 5 male names and their frequencies. I am using the following code for this purpose

tuesdata <- tidytuesdayR::tt_load('2022-03-22')
babynames <- tuesdata$babynames

top5_male <- babynames %>%
  filter (sex == "M") %>%
  group_by(name) %>%
  mutate(total = sum(n)) %>%
  select(name, total) %>%
  arrange(desc(total)) %>%
  distinct(name, total) %>%
  head(5)

babynames %>%
  filter(name %in% c("James", "John", "Robert", "Michael", "William")) %>%
  streamgraph("name", "n", "year")

However, when I run this code, it gives an error saying that

Warning message:
In widget_html(name = class(x)[1], package = attr(x, "package"),  :
  streamgraph_html returned an object of class `list` instead of a `shiny.tag`.

I looked up some solutions on the internet. However, none of them solved this problem. If you can help, I would be glad for that. Thank you in advance.

1 Answers

What you call an error is just a warning. The issue with your code is that you have not filtered the data passed to streamgraph for male observations. Fixing this will display your desired stream graph:

library(dplyr)
library(streamgraph)

babynames <- tidytuesdayR::tt_load('2022-03-22', download_files = "babynames")
babynames <- babynames$babynames

top5_male <- babynames %>%
  filter (sex == "M") %>%
  group_by(name) %>%
  mutate(total = sum(n)) %>%
  select(name, total) %>%
  arrange(desc(total)) %>%
  distinct(name, total) %>%
  head(5)

babynames %>%
  filter(sex == "M", name %in% c("James", "John", "Robert", "Michael", "William")) %>%
  streamgraph("name", "n", "year")
#> Warning in widget_html(name = class(x)[1], package = attr(x, "package"), :
#> streamgraph_html returned an object of class `list` instead of a `shiny.tag`.

Related