I am storing some “clipboard” content in a dcc.Store
. This content is only needed on the current page and should be deleted once the page is reloaded or switched to another page.
I have placed the dcc.Store
at the top of the layout hierarchy like this:
app.layout = html.Div(
className="container",
children=[
dcc.Location(id='location', refresh=False), # represents the URL bar, doesn't render anything
dcc.Store(id='memory'), # HTML5 local storage
navbar,
aspect_area,
]
)
(I assumed this is mandatory. Would a dcc.Store
object that is newly created when switching to the page solve the problem?)
I tried clearing the storage whenever the page changes, but the problem is that there is already a callback assigned to that output - of course the one that stores things in it.
@app.callback(
Output('memory', 'data'),
[
Input('location', 'pathname')
]
)
def clear_clipboard(pathname):
"""Clears the HTML5 in-browser storage on each page switch"""
return None
How can I achieve storage that persists only while the user is on the page?