Hey, thank you! If I do it, it looks for example like that: Edit fiddle - JSFiddle - Code Playground – But I would like to exclude the whole code without any connection to observablehq anymore. Is it possible?
It looks to me like you’ve embedded the whole notebook. I recommend that you embed just the few cells that you need. Unfortunately, Jake didn’t name the image cell that I’m sure you want, which is why I forked the notebook and embedded those cells from there. Here it is in a JSFiddle.
Certainly, this thing could be re-implemented completely outside of Observable. There are a few convenient features of the Observable notebook that would need to be worked around. Specifically, you’d need to specify the file browser as a standard HTML component and hook up some event listeners to get buttons to respond. That’s not particularly hard but it’s not really within the scope of what we do here, since we all love using Observable!
Before doing that please be aware that the author of that notebook hasn’t specified a license yet. This means that strictly speaking the code may not be republished outside of Observable.
Putting aside Jake’s particular notebook and the associated licensing restrictions (thanks @Fabian), if you are willing to use Observable’s opensource runtime, you may download the code for any notebook and run it offline (provided the notebook doesn’t further require other online resources). The official guide to achieving this is here:
Of course, if you wish to recreate the visualization without using Observable’s open source reactive runtime, there are several more steps. It’s not always easy to convert a notebook into ‘vanilla’ JavaScript, but there are several other posts on this forum that help to provide insights into this prcess.
Thank you for your answer! Observable seems to be wonderful, and obviously has a strong and active community, that’s great. Just for this thing, I would prefer to have the code completely independent from it and as pure/clean as possible. Does this explain what I need to know?
Yes, that’s a good explanation (Bryan is a gifted teacher!). There are a few other resources, as summarized by Radamés here.
Somewhere on this forum, I think, (I didn’t immediately find it) is a link to a Github project that someone put together to help in these conversions. I will update if / once I come back across it
I hope you continue to raise questions and to be a part of the community! <3
It was planned just for myself, wanted to work with infographics based on that. But it would be also cool to make it available for everyone. It was thought to work standalone.
I hope you don’t mind me asking: Why does it have to work outside of Observable?
With Observable’s builtin reactivity, its bundled Standard Library and collaboration features this would be a lot easier to demonstrate, implement and iterate upon.
I made the switch from standalone JavaScript to Observable roughly four years ago, and I never looked back.
Probably you’re right. I just think as a beginner, it’s much easier to start with something that works simply on a local machine, without external scripts, and as less code as possible. But maybe it’s also fine then with just Observable.
I feel confident to say that you will find that in Observable.
To make the notebook from your initial post work as intended (render individual channels, download SVG), we only need to make two small tweaks (an example is linked at the end of this reply).
To get started, fork Jake Low’s notebook via the “Fork …” button in the upper right, which will create your own copy. You can now modify the new notebook without ever losing any changes.
Next, insert a new JavaScript cell (e.g. below the file upload field) with the following content:
viewof channels = Inputs.checkbox( // Builtin helper to create a list of checkboxes
[0, 1, 2], // Our checkbox values, in this case the color channel indices
{ // A couple of options
value: [0, 1, 2], // The initially selected values (all in this case)
label: 'Color channels', // A label for the form element,
format: d => ['red', 'green', 'blue'][d] // displaying the channel names instead of just numbers
}
)
viewof is an Observable keyword that lets us access the current selection via the variable name channels (if you’re curious about viewof you can read a short introduction here).
Now we go to the histogram cell and replace the last line
This will remove all histogram channels which aren’t selected in our checkboxes.
Finally, to download the SVG we simply need to click into the left-hand cell menu of the histogramVisualization cell and select “Download SVG”:
You can find an example fork here. Please note that I will remove that notebook in a couple of days, so be sure to create your own fork from Jake Low’s notebook.