Based on the most recent video, I converted my app to a multi-page app. but the callbacks no longer fire.
I’ve been working on the problem since yesterday morning. I am at a loss and hoping maybe someone else had the same problem, and was able to solve it. Because this is a Beta version, and there is not much information online, I will do my best to present this issue here, though I don’t really know where to begin.
The multi-page app layout looks fine. The dbc.Components (le.g. the dbc.Accordion format in app.py) also work. but the app no longer processes information. For example, I have a text area with a submit button in the home page (submit_recipe.py), but the submit button no longer works. It is difficult to diagnose the problem.
I realize this question is broad and requests a summary of possible reasons. I wish I could make it more specific, but I need to troubleshoot this time. I think part of the problem is that I had to convert the app.py from the standalone app into one of the “pages” in the pages folder. It is now submit_recipe.py.
I apologize for the amount of code shared, but it is the minimal, meaningful example. This is a very important question to me because the app would performs best in a multi-page app given the amount of information and its potential as a research tool. I was going to display the file structure, but it is too much to expect anyone to digest.
Thank you for your time.
Robert
1. Here is the code from submit_recipe.py that no longer functions:
It is the first Accordion item and its related callback/function.
First Accordion Item:
dash.register.page(__name__, path='/')
external_stylesheets=[dbc.themes.SUPERHERO]
app = dash.Dash(external_stylesheets=external_stylesheets)
server = app.server
app.layout = html.Div(
[
html.Br(),
html.H5("Welcome to Ingredible's Nutrition Assistant"),
html.Br(),
dbc.Accordion(
[
dbc.AccordionItem( # Step 1: Paste your recipe here.
[
html.Div("Please paste your recipe here.", className="mb-4"),
dcc.Textarea(
id="recipe-textarea",
value="",
style={"width": "100%", "height": 400},
placeholder="Please note: All information in brackets or parantheses will be deleted.",
className="mb-4"
),
dbc.Button(
"Submit Recipe",
id="recipe-textarea-submit-button",
className="me-2",
n_clicks=0
),
dbc.Button(
"Reset",
id="recipe-textarea-reset-button",
className="me-2",
n_clicks=0
),
html.Div(id="MSG-1"),
],
title="Step 1",
item_id="acc_textarea",
),
**Callback and Function for First Accordion Item:**
# This callback and function accepts and processes the recipe,
# producing an editable table of amounts, units of measurement,
# ingredients and modifiers essential to a nutritional profile.
# The user can edit this information in this table to
# ensure its accuracy before the final analysis
@app.callback(
Output('nutrients-review-datatable', 'data'),
Input('recipe-textarea-submit-button', 'n_clicks'),
State('recipe-textarea', 'value')
)
def update_output(n_clicks, value):
if n_clicks > 0:
print("Recipe submitted")
with open("temp/recipe_contents.txt", "w", encoding='utf-8') as recipe_contents:
recipe = value.split('\n')
for line in recipe:
recipe_contents.write(line)
recipe_contents.write('\n')
convert_unicode_fractions()
convert_regular_fractions()
prepare_recipe_text()
parse_recipe_ner()
validate_recipe_ents()
prepare_data_for_table()
with open("./json/recipe_ents_list.json", "r") as final_recipe_file:
data = json.loads(final_recipe_file.read())
return data