Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidden sections where @NTBonds are defined hide the output NTBonds #30

Closed
dmetivie opened this issue Sep 14, 2023 · 3 comments
Closed

Comments

@dmetivie
Copy link

When I create a section with all my @Bind @NTBonds etc, I typically want to hide it, but it seems to hide also the nice looking side panel.
Note that if I hide just the bond cell (not the section), this works as intended, displaying the output.
Is it a bug, or am I (again!) missing something?

@disberd
Copy link
Owner

disberd commented Sep 14, 2023

I assume you are talking about hiding from the ExtendedTableOfContents.

If this is the case, I added a function for this specifically in version 0.7.7

show_output_when_hidden(x)
Wraps the given input `x` inside a custom HTML code created with
`HypertextLiteral.@htl` that adds the `always-show-output` attribute to the
calling Pluto cell.
This makes sure that the cell output remains visible in the HTML even when the
cell is hidden using the [`ExtendedTableOfContents`](@ref) cell hiding feature.
This is mostly useful to allow having cells that generate output to be rendered
within the notebook as hidden cells.
The provided attribute will make sure (via CSS) that cell will look exactly like
a hidden cell except for its output element. When the output is floating (like
for [`BondTable`](@ref) or [`ExtendedTableOfContents`](@ref)), this will make
the cell hidden while the rendered output visible.
# Example usage
```julia
BondTable([bonds...]) |> show_output_when_hidden
```
The code above will allow putting the cell defining the `BondTable` within a
hidden part of the notebook while still rendering the floating BondTable.
Without this function, the `BondTable` generating cell would need to be located
inside a non-hidden part of the notebook.
# Note
When calling this function with an input object that is not of type `HTML` or
`HypertextLiteral.Result`, the function will wrap the object first using `@htl`
and `PlutoRunner.embed_display`. Since the `embed_display` function is only
available inside of Pluto,
"""
show_output_when_hidden(x::Union{HTML, HypertextLiteral.Result}) = @htl("""
$x
<script>
const cell = currentScript.closest('pluto-cell')
cell.toggleAttribute('always-show-output', true)
invalidation.then(() => {
cell.toggleAttribute('always-show-output', false)
})
</script>
""")
show_output_when_hidden(x) = isdefined(Main, :PlutoRunner) ?
show_output_when_hidden(@htl("$(Main.PlutoRunner.embed_display(x))")) : error("You can't call
this function outside Pluto")

The way you use it is that you simply call it on the output like so:

BondTable([bonds...]) |> show_output_when_hidden

This will make sure that when your notebook is hiding cells the output will still be displayed (for the cell that has show_output_when_hidden.)
At the moment the code will hide the cell input if the ToC is set to hide hidden heading, even if the cell itself is not below a hidden section.
I am gonna fix this in the rewrite of the package but it's not a big issue for the moment as you are anyhow likely gonna put this cell inside a hidden section and you'll have to show hidden section to modify the cell's content.

I know documentation is currently very poor but I plan on also improving this with the rewrite of the package (Unfortunately this still depends on a rewrite of PlutoDevMacros so it will not happen before weeks from now)

@disberd
Copy link
Owner

disberd commented Sep 15, 2023

@dmetivie here is a clearer video example

856c5493-a426-4081-9791-d0702a510f7f.mp4

@dmetivie
Copy link
Author

dmetivie commented Sep 15, 2023

Thanks ! You thought of every thing already!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants