# Write variables to file?

**URL:** <https://talk.observablehq.com/t/write-variables-to-file/6424>\
**Category:** Help\
**Created:** [April 6, 2022, 12:43am UTC](https://talk.observablehq.com/t/write-variables-to-file/6424 "2022-04-06T00:43:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlb](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@carlb](https://talk.observablehq.com/u/carlb)\
**Post date:** [April 6, 2022, 12:43am UTC](https://talk.observablehq.com/t/write-variables-to-file/6424/1 "2022-04-06T00:43:08Z")

</div>

Hi all, I’m a new observables user.

I plan to embed an observable notebook into my blog for my small blog community to play with.  
At the end of playing, they can press a submit button and the value of the four variables they have selected (via sliders) should be appended to a file. After a week I will use the data in the file to produce a statistical graphic back to the blog.

1. can this be done directly in the observable notebook (ie pass/append variables to a file)?
2. if not (I suspect), can the variables be passed from the iframe (embedded notebook ) to the parent frame in my blog page? (relatively easy to export from there)

Thanks

---

<div class="post-metadata">

**Author:** ![tophtucker](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tophtucker/32/4781_2.png) [@tophtucker](https://talk.observablehq.com/u/tophtucker)\
**Post date:** [April 6, 2022, 1:59am UTC](https://talk.observablehq.com/t/write-variables-to-file/6424/2 "2022-04-06T01:59:33Z")

</div>

Good question!

**Re: 1.**

You’re right that there’s no way to do that purely within Observable, in that Observable does not offer persistent storage. You can’t write to a file attachment or other built-in database. If you have a [database connected](https://observablehq.com/@observablehq/databases?collection=@observablehq/working-with-data) you can write to it (just a regular `INSERT INTO`), but that only works with private notebooks.

But you can call any API from a notebook, including posting data to it. Often you don’t wanna have to set up a server just for that purpose, so people have used stuff like Firebase and Airtable as lightweight writeable stores. @tomlarkworthy often magically appears in threads like because he’s done a ton of that: see [his Firebase wrapper](https://observablehq.com/@tomlarkworthy/firebase) and his expansive [serverless notebooks initiative](https://observablehq.com/@endpointservices/webcode).

**Re: 2.**

I’m a little rusty but I think security restrictions prevent you from accessing the parent window from inside the iframe. If you call `window.parent` from the notebook you’ll see “SecurityError: Blocked a frame with origin “[https://yourname.static.observableusercontent.com](https://yourname.static.observableusercontent.com)” from accessing a cross-origin frame.” (Your notebook code runs inside an iframe even on [observablehq.com](http://observablehq.com); when you use the iframe embed, it’s really an iframe within an iframe.) So you can’t use [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) to send a message from the iframe to your blog, because you couldn’t obtain a reference to your blog window.

So this might be a case for embedding the notebook more directly onto your blog (no iframe) [using the Runtime API](https://observablehq.com/@observablehq/downloading-and-embedding-notebooks). (Change the dropdown from “Iframe” in the embed modal.) E.g., [here’s an example](https://github.com/observablehq/examples/tree/main/react-dataflow) where, when a value changes, it calls a React useState setter function (the `return {fulfilled: setSelection}` part).

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [April 6, 2022, 6:35am UTC](https://talk.observablehq.com/t/write-variables-to-file/6424/3 "2022-04-06T06:35:48Z")

</div>

For this kind of light collaboration I would use Firebase ([Firebase and Firebase UI / Tom Larkworthy / Observable](https://observablehq.com/@tomlarkworthy/firebase)).

for an app with no realtime requirements and no security concerns I might just use the REST API directly without a client [Firebase Database REST API](https://firebase.google.com/docs/reference/rest/database)

---

<div class="post-metadata">

**Author:** ![carlb](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@carlb](https://talk.observablehq.com/u/carlb)\
**Post date:** [April 6, 2022, 12:11pm UTC](https://talk.observablehq.com/t/write-variables-to-file/6424/4 "2022-04-06T12:11:34Z")

</div>

Thanks for the leads @tophtucker and @tomlarkworthy, firebase option looks great. Will give that a go.
