--- title: "How to Embed an Observable Notebook in A Hugo Blog" date: 2020-11-02T11:38:49-05:00 author: Hongtao Hao slug: observable-hugo-embed draft: false toc: true --- Embedding an Observable notebook in a Hugo blog post is no different than [embedding it in a stand alone webpage](/en/2020/11/02/exporting-observable-notebook/). Also, you can read [this tutorial](https://visionscarto.net/observable-jekyll/) on [Observable Jekyll](https://visionscarto.net/observable-jekyll/). Although it used Jekyll as an example, it's exactly the same for Hugo. ## Direct embedding through `iframe` You can embed a visualization on ObservableHQ directly through an `iframe`. I talked about how to do it [here](en/2020/11/02/exporting-observable-notebook/#embed-directly-via-iframe). This is the result: ```js ``` If you don't want the logo at the bottom, or that you think the loading is too slow, you have to embed it manually, which is what I am going to talk about in this post. ## Manual embedding This part is almost exactly the same as [embedding in a stand-alone webpage](/en/2020/11/02/exporting-observable-notebook/#embed-manually). However, since in a Hugo blog post, the `head` and `body` are already defined, you don't need to define the `head` and don't need to manually write `

...

`, for which you can simply use Markdown (which is why Hugo is invented...). You should know that **within** a Hugo blog post, you can still (and herhaps need to) write `
...`. You can see the source codes of this blog post [here](https://raw.githubusercontent.com/hongtaoh/hongtaoh.github.io/sources/content/en/blog/2020-11-02-embed-observable-notebook-in-blogs.md). The below is what it looks like to manually embed this [Observable notebook](https://observablehq.com/@hongtaoh/explrable-data) of mine. ### 1. Dropdown menu: Select your favorite season!
## 2. Slider: Choose your confidence interval
Dataset:
## 3. Buttons
## Full width If you want the visualization to be full width, it's very easy to do so. Follow the instructions in [this tutorial](https://visionscarto.net/observable-jekyll/). Wrap the target visuzliation within a `div` that is classed (What? It's not a verb?) `fullwidth` (or any name you prefer), and define `fullwidth` this way[^1]: ```css .fullwidth { width: 100vw; position: relative; left: 50%; right: 50%; margin-left: -50vw; margin-right: -50vw; } ``` [^1]: It's not my creation, but the codes from [this tutorial](https://visionscarto.net/observable-jekyll/).