I have the data in a list and when I return the dcc.Graph then it doesn't return anything just a blank graph is displayed in front of me
Let me explain the code to you all In this code I want user to enter product name and if the product name is present in the table and the bottle column is greater than 0 then select those rows data. Now we have some rows having month and bottle(quantity) the month is repetitive as one product is there many times in one month with different bottle(quantity) so now I am calculating the unique months quantity of bottle sold After that I am inserting the unique month list and calculated quantity list to the data list as shown This data list is appearing correctly in the output as per my needs But after that I want it to be plotted in bar chart but its not working for me. So help me out here.
Code Snippets:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input,Output
import pandas as pd
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
db="trial"
)
cursor = db_connection.cursor()
app = dash.Dash()
app.layout = html.Div(children=[
html.H4('Sales Of February 2020 by MHD'),
html.Label('Product Name: '),
dcc.Input(
id='tfield',
placeholder='Enter the product name',
type='text'
),
html.Br(),html.Br(),
html.Div([dcc.Graph(id='my-output')])
])
@app.callback(Output('my-output','figure'),[Input('tfield', 'value')])
def callback(input_value):
df = pd.read_sql("select Month,Bottle from merge where Bottle>0 and ProductName=%s", db_connection,params=(input_value,))
mon=[]
data=[]
quan=[]
uni_mon=[]
uni_quan=[]
y=0
su=0
for i in df.itertuples():
mon.append(i.Month)
quan.append(i.Bottle)
uni_mon=list(set(mon))
v=len(quan)
for x in uni_mon:
su=quan[y]
while((y<v-1) and (mon[y]==mon[y+1])):
su=su+quan[y+1]
y=y+1
y=y+1
uni_quan.append(su)
data.append({'x':uni_mon,'y':uni_quan,'type':'bar','name':input_value})
print(data)
figure={
'data':data,
'layout':{
'title':'Graphhhh',
'xaxis':'Month',
'yaxis':'Quantity'
}
}
return figure
if __name__ == '__main__':
app.run_server(debug=False)
so result on shell is
Dash is running on http://127.0.0.1:8050/
* Serving Flask app "dashnew" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:8050/ (Press CTRL+C to quit)
127.0.0.1 - - [09/Oct/2020 18:36:33] "[37mGET / HTTP/1.1[0m" 200 -
127.0.0.1 - - [09/Oct/2020 18:36:33] "[37mGET /_dash-layout HTTP/1.1[0m" 200 -
127.0.0.1 - - [09/Oct/2020 18:36:33] "[37mGET /_dash-dependencies HTTP/1.1[0m" 200 -
[{'x': [], 'y': [], 'type': 'bar', 'name': None}]
127.0.0.1 - - [09/Oct/2020 18:36:33] "[37mPOST /_dash-update-component HTTP/1.1[0m" 200 -
[{'x': ['2月サマリー', '2月サマリー (Feb Sales)'], 'y': [1260, 4275], 'type': 'bar', 'name': 'M&C Brut Blan'}]
127.0.0.1 - - [09/Oct/2020 18:36:36] "[37mPOST /_dash-update-component HTTP/1.1[0m" 200 -
this is my result when I enter and no graph is shown on server
please help me out here I have updated my entire code and output that I am receiving while executing this code. I want to get the bar chart in the browser where its showing blank graph Its displaying blank graph to me whether I enter a product name or not. Help me out!
