I’m a data scientist and R programmer, so I’m new to Observable and mostly new to JS. I’ve been using ObservableJS successfully within a Quarto dashboard. My dashboard creates a plot based on user inputs. I can be a bit slow to render on some machines when too much data is selected, so I’d like to only generate the plot if a condition (based on the number of rows selected) is met. Otherwise I’d want to show text encouraging the user to further refine their selection. It doesn’t seem like an if/else statement works – the plot generates regardless of the condition. I think this is because Plot.plot() is a generator. Any suggestions for how to get this conditional behavior working?
Plot.plot returns an SVG element or an HTML figure element, not a generator.
I’m not especially familiar with Quarto’s implementation of Observable JavaScript… it’s possible Quarto is changing the way the code works somehow? You might have better luck asking for help in a Quarto forum.
Have you considered using Observable Framework instead? You might be able to use data loaders to preprocess the data to make the chart more efficient, or even use server-side rendering to precompute the charts. If you want help getting started with Framework, we’d be happy to help if you want to open a discussion on GitHub.
Thanks for clearing up the generator question. It makes sense now that you say that … this is the challenge with jumping in with limited JS knowledge!
I’ve been looking into the Observable Framework (and a post from Allison comparing Quarto and the Framework was helpful in understanding how they might compare). I have a high level question about this that I’ll ask in a Github discussion.