Hey everyone. I’m new to using plotly dash and creating web apps and need help with my callback function. My team created a recommendation model that takes a job title and number as input and outputs a list of recommendations, the amount of recommendations are based on the number inputted to the function. This model is in a .py file titled recco.
For the app, I’m trying to create a plotly table that updates based on the job title and number inputted. There will only be one column which will consist of the course recommendations. The input boxes are showing and I can type numbers and text in them but a table isn’t showing and changing which is telling me my callback is incorrect. Here is my code:
‘’'python
from dash import Dash, dcc, html, Input, Output
import dash_bootstrap_components as dbc
import plotly.graph_objects as go
import pandas as pd
import recco
app = Dash(__name__, external_stylesheets=[dbc.themes.ZEPHYR])
server = app.server
def fig1(course_list):
data = {'Course_Recommendations' : course_list}
df = pd.DataFrame(data)
fig2 = go.Figure(data = [go.Table(
header = dict(
values=["<b>Course Recommendations</b>"],
align='center', font=dict(color='black', size=12),height=30
),
cells=dict(
values=[df['Course_Recommendations']],
align='center', font=dict(color='white', size=11), height=30))])
return fig2
input_types = ("text", "number",)
app.layout = html.Div(
[
html.H1("Course Recommender"),
html.P('Please enter a job title and the number of recommendations you would like'),
html.Div([
dcc.Input(
id = 'my_{}'.format(x),
type = x,
placeholder = "insert {}".format(x),
debounce = True,
size = 25
) for x in input_types]),
html.Br(),
dcc.Graph(id = 'mytable')
])
@app.callback(
Output(component_id='mytable', component_property='figure'),
[Input(component_id='my_{}'.format(x), component_property='value')
for x in input_types
],)
def update_output(value):
get1 = recco.recommender(value)
return fig1(get1)
if __name__ =='__main__':
app.run_server(debug=False)
‘’’
All help is appreciated. Thank you.