Callback is receiving an error. Please help!

from dash.dependencies import Output, Input, State

app = JupyterDash(__name__)

#layout is saved to a variable so I dont have to keep running it
app.layout = layout

@app.callback(
    [
        Output("avg_table", "figure_") 
         
    ],
    [
        Input('avg_table', 'active_cell')
    ],
    [
        State('avg_table', 'derived_virtual_data')
    ]
)
def change_area_graphs(avg_cell, avg_data):
    print("test")
    row_number = avg_cell["row"]
    row_data = avg_data[row_number]
    type_value = row_data["type_label"]
    print("active_cell", row_number,"\nrow_number", row_data,"\nrow_data", type_value) 
    key = list(filter(lambda x: reversefactor[x] == type_value, reversefactor))[0]
    print(key)
    #return 0 
    return new_create_subplots(key)
    
app.run_server(mode='inline', height=800)

Error Message: message: ā€˜ID not found in layoutā€™, html: ā€˜Attempting to connect a callback Input item to comā€¦he callback(s) for Output(s):\n avg_table.figure_ā€™

Hi @marlainna456 welcome to the forums.

Delete the underscore form ā€˜figureā€™:

Thank you so much! Do you have any idea why my print lines are not showing when I run my cells.
If I run
print ā€˜hello worldā€™

The line prints but the lines in my code above does not.

tried
import sys
reload(sys)
sys.setdefaultencoding(ā€œutf-8ā€)

does this have to be in the first cell of my notebook to work?

hi, have you tried display(ā€˜hello worldā€™)?

Hello, thanks for the follow up I did try the display(ā€˜hello worldā€™) and it did not work. I am using JupyterDash notebook. Also, I tested removing the underscore in figure and it did not work as well. Any additional advice?? thanks in advance

hello yes and my call back is still not working

Average_tab = create_tab(avg_table, ā€œAverageā€, ā€œaverageā€)

Avg_tab = dcc.Tabs(
[Average_tab],
className=ā€œtabs-containerā€,
id=ā€œAvg-tabsā€,
value=ā€œaverageā€,
style={ā€˜gridAreaā€™: ā€œavg_tableā€}

)
figure = html.Div([

dcc.Graph(figure=fig,
style={ā€˜gridAreaā€™: ā€œfigureā€})
]
)

container5 = html.Div([ Avg_tab ,figure ],
style={ā€˜displayā€™:ā€˜gridā€™,
ā€˜gridTemplateAreasā€™: ā€™ " avg_table figure ',
ā€˜gridTemplateColumnsā€™:"50vw 50vw ",
ā€˜columnGapā€™: ā€˜10pxā€™})

layout = html.Div([title, container5])

app = JupyterDash()
app.layout = layout
#app.run_server(mode=ā€˜inlineā€™, height=500)
app.run_server(mode=ā€œinlineā€, height=500,host=ā€œlocalhostā€,port=8055)

------ Call back code ----

from dash.dependencies import Output, Input, State

app = JupyterDash(name)

#layout is saved to a variable so I dont have to keep running it
app.layout = layout

@app.callback(
[
Output(ā€œavg_tableā€, ā€œfigureā€)

],
[
    Input('avg_table', 'active_cell')
],
[
    State('avg_table', 'derived_virtual_data')
]

)
def change_area_graphs(avg_cell, avg_data):
print(ā€œtestā€)
row_number = avg_cell[ā€œrowā€]
row_data = avg_data[row_number]
type_value = row_data[ā€œtype_labelā€]
print(ā€œactive_cellā€, row_number,ā€œ\nrow_numberā€, row_data,ā€œ\nrow_dataā€, type_value)
key = list(filter(lambda x: reversefactor == type_value, reversefactor))[0]
print(key)
display(ā€˜hello worldā€™)
fig1 = new_create_subplots(key)
return fig1

app.run_server(mode=ā€˜inlineā€™, height=800).

Please note if I run my function outside of call back it returns the figure. For example: fig = new_create_subplots(1) return my figure

What if it is set like this,
app.run(debug=True)

hello,
I tried the app.run(debug=True)
error: AttributeError: ā€˜JupyterDashā€™ object has no attribute ā€˜runā€™

also tried:
app.run_server(mode=ā€˜inlineā€™, height=800,debug=True)

I did NOT receive an error but the print message did NOT appear either . I am open to try anything at this point

emm, I think you can put an empty div to output your print.

@app.callback(
    [
        Output("your-fig", "figure") ,
        Output('print-div', 'children')
         
    ],
    [
        Input('avg_table', 'active_cell')
    ],
    [
        State('avg_table', 'derived_virtual_data')
    ]
)
def change_area_graphs(avg_cell, avg_data):
    ....
    return new_create_subplots(key), str({"row_number": row_number}) 

Hi Stu,
I sure do appreciate your help! Unfortunately the printing using an empty div did not work.

I am a newbie but is there a way for me to see the output in the console if I right click and inspect the page. I dont see how but I really dont have a ton of experience with this type of thing

I found the error but how do I fix it?

Here is my table:

avg_table = DataTable(
id= ā€˜avg-idā€™,
columns=avg_columns,
data=avg_data,

How do I add my table in a DIV with the id so I can reference it in my callback

hi @marlainna456 ,
You didnā€™t put this empty div in your layout, did you?
Just make your layout look like this.

app.layout=html.Div([
    dt.DataTable(),
    html.Div(id='print-some-info')
])

It seems that you didnā€™t being in touch with dash for too much time, I recommend you to subscribe to @adamschroeder 's channel, which can help you quickly find what you donā€™t understand now.

1 Like

Thank you @stu

hi @marlainna456
Can you please put your code in preformatted text so itā€™s easier to read.

layout = html.Div([title, container5])

I see this in your code. This layout does not have an ID. Thatā€™s why one of the error messages is: ID not found in layout.

Hi Adam, I am honored to hear from you. I was just watching one of your videos. Thank you. I am away from my computer right now. Thing is I donā€™t know how or where to add the ID. I am a fan. Just fyi. I am new to this and I have been spinning my wheels for day on this issue

Hi @marlainna456
I think you can learn Dash very quickly. Here are a couple of things I think could help you.

1 Like

Problem solved! Thanks

1 Like

Also, I went to my localhost:8888 site and entered my terminal token password for jupyter notebook and now my print messages are showing up as well All good!

1 Like