Feature request app.ResetOnPageReload

I believe the project I’m working on would benefit others. In this project, a cron job gets the latest bitcoin value every minute, from an CryptoCompare API call, and writes it to Sqlite. My simple Dash app then shows the latest 15 minutes. The whole thing is run on a commodity cloud VM. It’s on github.

My problem now (sorry) is that Dash is not behaving in what I believe is often the user’s expectation. When one refreshes a page in the browser one often expects the whole page to be rebuild. Of course, Dash and others don’t do this because they assume the user won’t want their current state deleted. It’s up for debate.

I read through the various ways one can deal with state in Dash and again, MAJOR HEADACHES! Which method is best for me? How long will it take me to learn each complicated technique?

So if I had an app.ResetOnPageReload = True then Dash could just reload the page, no matter how “expensive” when a user refreshes the whole page in their browser. Then later, if I want to fine tune behavior, I could let it default to false and wrap my head around those techniques of state.

Can this be done? Is there a gunicorn trick?

You can achieve this by assigning a function to app.layout. It will be executed each time the page is refreshed, allowing you to include whatever updating logic you like.

See the documentation on live updates here. In particular the “Update on page load” section.

1 Like

Thanks! When I woke up even that looks too much to deal with, but on second look might not be so bad. Will try. I did move my app layout to a function, but that made no difference.

Another request I have for the Dash team is more comments, for example, in the above:

# pip install pyorbital
from pyorbital.orbital import Orbital
satellite = Orbital('TERRA')

What is ‘TERRA’ is it made up variable, or a constant or object if Orbital? Again, I just want it to update, no become an expert in yet ANOTHER library :wink: Looks like that’s weird library to use, okay, so instead of ‘TERRA’, “mySatTimer”, or something like that. THANKS AGAIN!

I’m sorry to keep whining, but the less time I spend on these unknowns to me the more I can focus on core Dash development! And I still believe a simple page reload should be part of Dash’s app object.

AH I SEE, the Orbital thing is just an example of something you may want to have updated. Why import a library? Can’t you just use system time or something?

Okay, I tried it, it’s in webapp2.py in my git repo. Didn’t work. No idea what I’m missing.

The page that never reloads can be found here: http://34.70.26.167:8000/ though it may be down while I’m working on it at any time.

I tried another suggestion @chriddyp made in a different thread. I added:

html.A('Refresh', href='/')

Unlike hitting refresh multiple times in the browser, that link will occasionally refresh the whole page; that is, rebuild the dataframe from SQLite. however, it seems to hang for a big, as if must wait for gunicorn to free up a worker. Or put another way, it only seems to work if the page has maxed out server requests. Anyway, doesn’t work reliably.