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