Is it possible to use await visibility on a scrubber?

Morning,

I’d like to wait to have a scrubber run until the cell is visible. Is this possible using await visibility()? I’ve tried without success, but wonder if there is a work around.
Thanks

This seems to work for me:

viewof x = {
  await visibility();
  return Scrubber(d3.range(1000), { delay: 1000 });
}

Demo in notebook here. Let me know if you have any questions or an example where it’s not working!

1 Like

Odd! I was using the same code it wasn’t having any luck. I’m now finding some odd be behaviour. When I have developer tools open and clear my cache it works as expected. When the dev tools are closed and I refresh the browser the cell starts running before I reach it. In incognito it works the first time, but likewise not if I refresh the notebook. Perhaps this is just how it works…

Here is my example. currentDate is the cell, which then runs the animation in the next cell.

Appreciate you looking at this!

Well, the cell is temporarily within the viewport while all the cells above it are still running. You could either declare explicit dependencies on the prior cells, or insert an await Promises.delay(1000); before your await visibility(); to give the notebook some time to load (and push the cell down below the viewport).

1 Like

Yeah, I noticed that so I pushed those cell further down the notebook :). Good solution, thanks!