Dealing with large tables as inputs to charts.

Hello,

Apologies if this isn’t the right place, I’m loving observable but due to the way results are delivered I’m using R/Quarto + OJS, with pretty much everything on page being driven by OJS. I am working with a large dataset for a client and they want to plot charts where they can define the axis content. It’s things like food ingredients vs brands and they’ll be selecting more than one. As you can imagine there’s thousands of ingredients and hundreds of brands out there so a simple dropdown isn’t good enough.

I thought I had this solved when combining Inputs.search and Inputs.table but you can’t build up inputs using this method because as soon as you change the search it re-renders the table and looses the previous values. I found a great post that solves this but it only works on ObservableHQ, and won’t work in the Quarto OJS runtime; Filtering a selection / Fabian Iwand | Observable .

Does anyone have any thoughts on how I could get around this? I think a searchable input table is the best solution but it obviously needs to retain any previous selections.

That’s surprising. I’m not familiar with Quarto’s runtime version, but I’d expect that nothing in the described solution would prevent you from using it in Quarto?

Fabian’s notebook seems to work fine in Quarto to me. I literally copied the code cells from the notebook into ojs cells in Quarto, previewed the result and it seemed to behave identically.

Oh, that’s interesting. Thank you for checking.
I’ll check I’ve got the latest versions of everything installed and see if a test will work. :crossed_fingers:

Hi @mcmcclur

I still couldn’t get my small demo working when I tried this morning. Tested in Safari and Chrome and my quarto check show’s nothing to be out of date.

Could I ask more detail on how you ran your test please? I used Rstudio and copied everything from the notebook into ojs chunks then rendered. My check to see if it’s working as expected was to filter for Chinstrap select two at random and then change the filter to something else before going back to Chinstrap. On Observable HQ the two I select are still selected, but locally I’m still getting the data reset.

Thank you

Sure! I don’t use RStudio. I often use Python within a Jupyter notebook but, when writing documents with Quarto, I typically write .qmd files with ojs cells. I simply copy/pasted the code cells from Fabian’s notebook into those types of cells. For example, to import his retainSelection function I included the following in my .qmd file:

```{ojs}
import {retainSelection} from "@observablehq/fabians-toolbox"
```

I did that with every code cell and then ran quarto preview from the command line. I’m a bit busy today but could post to GitHub later, if necessary.

Thanks for the help Mark. It sounds like your .qmd file will be identical to mine as that’s all I’ve done with the exception that I was hitting “render” in RStudio as opposed to quarto preview. I’ve just tried quarto preview on my .qmd but the result was the same, changing filters looses any changes to selections previously made :frowning: .

The javascript console was clear of errors too. I think I’m stuck at this point.

I suspect that you have an upstream cell that causes your data cell to invalidate, and the selection state to get lost.

Be sure to replicate the example notebook to the letter (without any adjustments, no matter how small) so that you have a working baseline you can return to.