Reputation: 360
I have a function that returns a figure directly and I want that figure to be placed in layout's Div. The fact is that as far as I know, is not posible to return this type of object in a callback
I do not know how to solve this problem to return the figure. Next, I would have to modify that figure too.
The function that returns the figure:
fig=plt.figure() #set up the figures
fig.set_size_inches(7, 5)
ax=fig.add_subplot(1,1,1)
draw_pitch(ax) # Here I draw some lines over the figure
ax.plot()
return fig
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from utils import p_number, plot_pitch
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Input(id='my-id', value=p_number(7), type='text'),
html.Div(id='my-div')
])
@app.callback(
Output(component_id='my-div', component_property='children'),
[Input(component_id='my-id', component_property='value')],
[State('local', 'data')]
)
def update_output_div(input_value):
return plot_pitch()
if __name__ == '__main__':
app.run_server(debug=False)
Upvotes: 1
Views: 5048
Reputation: 27370
Dash supports figures generated with plotly
but not matplotlib
as you appear to have done here... Here is the related documentation: https://dash.plot.ly/interactive-graphing
Upvotes: 2