I'm a beginner in Flask(python). I'm stuck on this problem for quite a long now. I need to show plots on webpage based on the plot type selected in a dropdown list. I am able to add the Dropdown list which shows on the webpage. But I'm stuck in applying conditions based on the selected item in a dropdown list.
HTML code for dropdown list:
<select name="Selected_plot" method="GET" action="/visualize">
<option value="{{Selected_plot[0]}}" selected>{{Selected_plot[0]}}</option>
{% for plots in Selected_plot[1:] %}
<option value="{{plots}}">{{plots}}</option>
{% endfor %}
</select>
Python Code:
@app.route('/')
def home():
Selected_plot = ['Scatter plot', 'Line Plot','Box Plot']
return render_template('homepage.html' ,Selected_plot =Selected_plot)
@app.route('/visualize')
def visualize():
"""
if Selected_plot = 'Scatter plot':
#Scatter plot code
elif Selected_plot = 'Line Plot':
#Line plot code
else Selected_plot = 'Box plot' :
#Box plot Code
"""
canvas = figurecanvas(fig)
img = io.BytesIO()
plt.tight_layout()
fig.savefig(img)
img.seek(0)
return send_file(img,mimetype = 'img/png')
I would really appreciate it if anyone in the community try to help me.
Thanks in advance