Commit d9ca9ead authored by Samir Mena's avatar Samir Mena 👽
Browse files

First Commit

parent 9927d706
''' Start simple with Dash / Plotly '''
import pandas as pd
import as px
import dash
from dash import dcc
from dash import html
from dash.dependencies import Output, Input
app = dash.Dash(__name__)
#---------------------- auto run the broswer------------------------#
import webbrowser
#-----------------------------dataframe works ------------------------#
''' the data analysis task is to count the Down, No ,
Steady and Up for every mediceince and graph it'''
data_frame = pd.read_csv('diabetes_data.csv')
data_frame = data_frame.loc[:,'metformin':'metformin-pioglitazone']
df = pd.DataFrame() # empty data frame to collect "column in data_frame.columns"
for column in data_frame.columns: # for each colum labeled with midicne do the following
df1=data_frame[column].value_counts() # count the occurance of (Down, No, Steady, Up) for each medicine
print(df1) # tst output
df=df.append(df1) # append / accomulator @ self
df = df.T # transpose
df.index.rename('Catagory', inplace=True) #the indixing problem
df.reset_index(level=0, inplace=True) #the indixing problem
df.to_csv('append.csv') # tst output
#fig1 =, x='Down', y='metformin')
#fig_md = px.pie (df, names='Catagory', values='metformin')
#fig2 =, x='Catagory', y='metformin',barmode="group" , color='Catagory')
#fig = px.scatter(df, x="month", y="sales",size="sales", color="month", log_x=True, size_max=60)
#fig3 = px.pie (df, names='month', values='sales')
#fig4 = px.pie (df, names='month', values='cost')
#------------------------------app layout-------------------------#
app.layout = html.Div([
html.H1('Diabetes Medicine Abstraction '),
dcc.Dropdown(id='medicine' ,
options=[{'label' : medc , 'value' : medc}
for medc in data_frame.columns ],
value ='metformin'
dcc.Graph(id="fig_bi" , figure={}), # the bi graph in html page
dcc.Graph(id="fig_bar" , figure={}), # the bar graph
@app.callback( # the link between def lst_update(value_in) > app.layout
Output(component_id = "fig_bi", component_property = 'figure'), #link to dcc.Graph(id="fig_bi" , figure={})
Output(component_id = "fig_bar", component_property = 'figure'),
Input(component_id = 'medicine', component_property = 'value')
def lst_update(value_in):
dff = df[['Catagory',value_in]]
#dff.to_csv('dff.csv') # index see
#print(dff) tst dff
fig_md = px.pie (dff, names = 'Catagory', values = value_in)
fig_bar = fig2 =, x = 'Catagory', y = value_in ,barmode="group")
return fig_md,fig_bar
#----------------------------debug server------------------------#
if __name__ == "__main__":
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment