Hello,
I want to create a multipage app with the ServersideOutputTransformation so that I can access data generated on one page on another page. For this, I have oriented on this instruction. I also tried this approach from the forum.
The usage of background callbacks as here in the example as well as in the documentation are not possible for me, because the callbacks should only be executed when triggered and not multiple times in the background
My goal is, that I can simply return a variable as an Output from a callback-function and use it somewhere in my application on any page. Just as long as the ID is mentioned as an input to the callback-function
The current code structure is as follows:
app.py:
import dash
from dash import Dash
import dash_bootstrap_components as dbc
from dash_extensions.enrich import DashProxy, Output, Input, State, Serverside, html, dcc, ServersideOutputTransform, FileSystemBackend
# styling the sidebar
SIDEBAR_STYLE = {}
LINK_STYLE = {}
PARAMETERS, APP = core.authFun.initiate(user=None)
app = DashProxy(__name__, use_pages=True, transforms=[ServersideOutputTransform()])
#definition of the sidebar. Use HTML components
sidebar = html.Div([])
app.layout = dbc.Container([
dcc.Location(id='url', refresh=False),
sidebar,
dash.page_container
])
@app.callback(
[
ServersideOutput('oID', 'data'),
],
Input('url', 'search'),
background=True,
)
def getAADToken(queryParameter): #Just run on trigger input
acquire_tokens_result = {'initial': 'runApp'}
oID = ''
if queryParameter != '' and 'code' in queryParameter:
...
...
...
oID = 'just mocked, the value gets generated by function and is a String'
return oID
if __name__ == '__main__':
app.run(host = 'localhost', port = '8050', debug=True)
The file I want to use the contend of ‘oID’ is as follows:
adp.py
import dash
from dash_extensions.enrich import DashProxy, Output, Input, State, Serverside, html, dcc, ServersideOutputTransform, FileSystemBackend
import dash_bootstrap_components as dbc
dash.register_page(
__name__,
name = 'ADP',
path = '/adp')
CONTENT_STYLE = {}
app = dash.get_app()
workspacesSelect = html.Tr([
html.H2('Select a workspace:', style={'width': 550}),
dcc.Dropdown(
id='workspaceDropdown',
),
])
...
... I have left out the whole layout of the page because it is not relevant
...
#### Functions with callback
@app.callback(
Output('workspaceDropdown', 'options'),
[
Input('url', 'pathname'),
Input('oID', 'data')
],
)
def getWorkspaces(path, oID):
try:
if path == '/adp':
workspaces = get_workspaces(oID) #here I want to use oID which I get from app.py
workspacesList = list(workspaces.keys())
return workspacesList
except IndexError as e:
None
return []
The structure of my repository is as follows
app.py
*pages*
|--- adp.py
|--- otherpage.py