-
I'm trying to set up a situation where a plot is only created or displayed (I'd be fine with either, but the ultimate point is not to display it) if a certain condition is met. However, I keep running into problems, and it's either a bug or my lack of understanding of generators, promises, etc. But I think it's a bug. Since my code is complex, here's a very basic alternative that causes the same bug. (N.B. When it's a plot, not an Input, I can get it to work if I don't assign the plot to a variable, by embedding the plot creation inside a template literal -- but I'm going to need the value of the user-selected cell at a later point, so I need to assign it to a variable.)
The way I understand flow logic, when
If I take the creation of
Thanks in advance for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Only variables created at the top-level of a code block are visible outside of it. You could maybe replace your second block with: const testInput = testTF === true ? html`<input type=range step=1 min=1 max=15>` : null;
const n = testTF === true ? view(testInput) : null; |
Beta Was this translation helpful? Give feedback.
-
And would that work with Plot, as well as Input? (The Input in my original
example was only for the sake of simple demonstration.)
Thanks!
…On Sat, Mar 15, 2025, 12:07 PM Philippe Rivière ***@***.***> wrote:
view and display are not meant to be used in ${……} interpolation tags;
but you can name your input widget. For example:
```jsconst widget = Inputs.range(); // an HTML range inputconst value = Generators.input(widget); // The async generator bound to the value of the widget```
${widget}
Hello, ${value}.
In the example above Generators.input is identical to view, but it does
not try to display the widget in that block (since it will be displayed in
the interpolated Markdown).
https://observablehq.com/framework/reactivity
—
Reply to this email directly, view it on GitHub
<#1946 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3ALFGLHZW5PZUEB2IEGLTD2URF4DAVCNFSM6AAAAABZCRSRUOVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTENJRGA3DQNI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
Only variables created at the top-level of a code block are visible outside of it. You could maybe replace your second block with: