Blogdown and Streamgraph

Hi,

I'm trying to populate an analysis with streamgraph on blogodown. However, I'm getting the below message indicating that the graphs won't populate.

Objects that have dep endencies (e.g. HTML widgets) do not work when the output format is Markdown instead of HTML.

What change should I implement in my code?

Data_set%>%
  filter(Country %in% c("United States", "China", "Germany", "United Kingdom", "France", "Japan", "Netherlands",...)) %>%
  streamgraph("Country","Exports","Year", interpolate="cardinal", interactive=TRUE)%>%
  sg_fill_tableau(palette = "tableau20") %>%
  sg_legend(show=TRUE, label="Country: ")%>%
  sg_axis_x(tick_units = "Year", tick_interval= 2)%>%
  sg_axis_y(0)

Thanks

It's hard to know for sure, since you are not providing a REPRoducible EXample (reprex), but I suspect that your problem is with the YAML header for your .Rmd file instead of your code for the steamgraph.

Take a look at this example.

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(babynames)
library(streamgraph)
```

Column {data-width=650}
-----------------------------------------------------------------------

### Chart A

```{r}
babynames %>%
  filter(grepl("^Kr", name)) %>%
  group_by(year, name) %>%
  tally(wt=n) %>%
  streamgraph("name", "n", "year")
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

```{r}
babynames %>%
  filter(grepl("^I", name)) %>%
  group_by(year, name) %>%
  tally(wt=n) %>%
  streamgraph("name", "n", "year", offset="zero", interpolate="linear") %>%
  sg_legend(show=TRUE, label="I- names: ")
```

### Chart C

```{r}
plot(iris)
```

3 Likes

Hi @andresrcs. Thank you very much for your reply. I appreciate it.

Yes, your code and flexdashboard would work. However, the YAML header is slightly different when working with blogdown.

In my example, this is my YAML header for my RMarkdown in my blogdown. I believe it doesn't populate the streamgraphs because the streamgraph package is an htmlwidget.

```
title: "Title"
author: Name
date: '2019-04-07'
slug: world-analysis
categories:
  - R
tags:
  - R Markdown
  - streamgraph

```

Thanks,

1 Like

From your error, I am guessing you are using .Rmarkdown as your post content type, rather than .Rmd. If so, try using the new post add-in and selecting .Rmd instead of .Rmarkdown.

Roughly:
.Rmarkdown post --rmarkdown--> md --blackfriday markdown processor + Hugo--> html
.Rmd --blogdown/bookdown/rmarkdown+pandoc --> html

4 Likes

Hi @apreshill,

Thank you very much. Yes, that's right. I've just changed to .Rmd and it works.

Thanks again for your help and time. Much appreciated.

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.