It absolutely can be done. Hiding cells and running them at initialization is supported by default: https://jupyterbook.org/en/stable/interactive/thebe.html. ipywidgets are already supported, just do %pip install ipywidgets. There's some sort of issue with them at the moment which requires extra code to fix:
@mguichard Ah, that's more than I thought, but not there yet...
Just to clarify, I'd like to use ipywidgets in combination with Thebe so that a Python-kernel can do the required calculations after a change in the state of the widget, with the code hidden because I only want the interactive result to be shown to the reader. If I use widgets without a Python-kernel it gives a 'static' ouput with a fake widget.
Your code does work, but only in existing cells, not in added cells (top figure was existing in ipynb-file, bottom one was added in the browser):
I've a (ugly coding) example from my first-year class in which the text output loads, but the figures are very weird. Could you have a look at that whether we can get that working? See 35ea8d56 :
Are the ipykernel lines required because of an issue with ipywidgets itself? Or with ipywidgest in combinations with thebe? In the second case I would say we need to automatically fix it so that other users don't have to think about it.
Furthermore, it seems the tag hide-input breaks the thebe-functionality for the entire page. But maybe that was caused by impatience of the local server not running yet.
Interesting observations. The add cell button is a bit of a hack, so I'm not surprised it broke in this case. Thank you for bringing it to my attention. The ipykernel fix just seems to be for Thebe, I can automate that too for the time being. I'm going to play around with the hide and init tags a little later, I'll keep you updated!
@mguichard , when i do remove-input, the output of the cell is not shown either. Furthermore, the other cells on the same page don't display any output.
If I use hide-input, it works indeed (it must have been my impatience, updating files and then rerunning build-lite.sh sometimes seems to stall) but hides the output as well.
Yep, you're right about thebe-init. I'm putting together a MR that fixes that + more intuitive behaviour for hide-input (so the output can still be displayed). I'll see if I can also get remove-input to work as well!
@tomvanwoudenbe Could you check out !32 (merged) please! Unfortunately I cannot get remove-input to work natively because it doesn't actually generate any input HTML (needed by Thebe), but I've added a special thebe-remove-input tag that does what you would expect (hopefully). The merge request already edits the example you provided, so you can see the new features/bug fixes.