If we for any reason backed up a notebook by downloading it and removed the same from the observable platform is there a simple way to upload the js file back to create a new notebook later?
This isnât currently supported, no, sorry. The downloaded tarball contains the compiled code rather than the source code of the notebook.
The following is related, but is not really âsimpleâ and doesnât quite do exactly what you want: There are some (unofficial, possibly discouraged, possibly no-longer-working) nodejs scripts in this thread which let you make API calls to api.observablehq.com to download and upload the ânotebook JSON fileâ that the observablehq.com editor uses internally to store the source of notebooks â feel free to post in that thread if you try them out and have issues. (I havenât looked at this stuff in many months, so itâs possible that my understanding is way out-of-date.)
This is close to what youâre asking for, however, as @mbostock said, the .tgz
files contain only the âcompiledâ version of your notebook and not the original notebook JSON source. So if you only have the .tgz
and not the JSON source, then even if the scripts above work, youâre still out of luck for now. In principle the compiled ES modules could be decompiled (I wrote some code which does that for the output of the old v1 version of the runtime here) but this wouldnât be perfect and you would still lose some information (e.g. the pinned vs unpinned status of each cell).
Possibly also of interest: @asg017âs âUnofficial ObservableHQ Compilerâ project can ârunâ the notebook JSON source files using the Observable runtime (see compile.notebook
). Currently this acts more like an âinterpreterâ than a âcompilerâ since it has to re-parse the original source on each page refresh. I do hope to add some âsource-to-source compilationâ functionality there to output ES modules like the export button on observablehq.com does in the near-ish future (see this issue).
Thank you! This is very helpful.