embed notebook with params

I want to create multiple versions of a plot by using params. This is my notebook: Temperatur regional / RND / Observable

Is there a way to embed it with a given param? (I use this notebook for embedding: Handy Embed Code Generator / Jeremy Ashkenas / Observable)

You can get query parameters in embedded notebooks this way:

new URLSearchParams(document.location.search).get("cell")


new URL(document.location.href).searchParams.get("cell")
1 Like

thank you, I added a cell with this code. But I don´t know how I to set a param in the embed code. This ist my embed code (first cell): Temperatur regional / RND / Observable

I think it’s pretty fully documented here:

When I add a param in the url it works fine: Temperatur regional / RND / Observable

But when I embed parts of the notebook the param gets lost: https://observablehq.com/embed/@rnd/temperatur-regional?cells=title%2Cviewof+plz_input%2Canswer%2Clegend%2Cchart%2CmyStyles

@jchrist “cell” was just an example for a parameter name. You need to replace it with your own, e.g. “ort”, as the names “cell” and “cells” are already reserved for the selection of cells that are shown in an embedded notebook. Sorry that I didn’t make this clear.

sorry, I am not familiar enough with these things, still need your help. I changed the name of the param to “ort” but don´t know how to integrate “?ort=Stuttgart” in the embed code (see first cell, my favorite method) or the standard embed code: https://observablehq.com/embed/@rnd/temperatur-regional?cells=title%2Cviewof+plz_input%2Canswer%2Clegend%2Cchart

@jchrist Append it to your embed URL as &ort=Stuttgart. The “?” is used to mark the beginning of the query string, while individual parameters are delimited by “&”.

1 Like

thank you, that works great! Is there a way for this embedding method, too? Handy Embed Code Generator / Jeremy Ashkenas / Observable

I guess this would mean to append it somewhere here: https://api.observablehq.com/@rnd/temperatur-regional.js?v=3

No, this is just the module URL. How you fetch the query depends on how and where your embed code is integrated. Since custom embeds are a pretty advanced feature I would recommend to stick with iframe embeds instead.