Hello,
I’m fairly new to Dash and created a callback with a dbc.Input that takes the value of user input and creates the title of the analysis the user is completing on the app. This input is then used as the filename in a download to excel. This issue I’m having is that once I select download, my app calcs stop working if a want to rerun my numbers and will only work again after changing the dbc.Input. I was wondering if there is any way to get around this?
Input in Layout:
dbc.Input(id="titleinput", placeholder="Title Analysis Here..", type="text"),
Callbacks for input value and download:
`#Title Input
@CAD.callback(Output("titleoutput", "children"),
Output("titleoutput1", "children"),
Output("titleoutput2", "children"),
Output("titleoutput3", "children"),
Output("titleoutput4", "children"),
[Input("titleinput", "value")])
def output_text(value):
if value is not None:
return value, html.H1(str(value), id='titleoutput1'), html.H1(str(value), id='titleoutput2'), html.H1(str(value), id='titleoutput3'), html.H1(str(value), id='titleoutput4')
else: return '','','','',''
#download to xsxl
@CAD.callback(
Output('download', 'data'),
Input('download', 'n_clicks'),
Input('netimpacts', 'data'),
Input('Investment_To_Gross_Impact','data'),
Input('Investment_From_Gross_Impact','data'),
Input('Investment_To_Assumptions','data'),
Input('Investment_From_Assumptions','data'),
State("titleinput", "value")
)
def export(n_clicks, netimpact, invto, invfrom, ato, afrom, value):
netdf= pd.DataFrame.from_dict(data=netimpact)
df1= pd.DataFrame.from_dict(data=invto)
df2= pd.DataFrame.from_dict(data=invfrom)
df3= pd.DataFrame.from_dict(data=ato)
df4= pd.DataFrame.from_dict(data=afrom)
filename= (str(value)+'.xlsx')
writer= pd.ExcelWriter(filename, engine='xlsxwriter')
netdf.to_excel(writer, sheet_name='Net RAF Impacts', index=False)
df1.to_excel(writer, sheet_name='Inv To Gross Impact', index=False)
df2.to_excel(writer, sheet_name='Inv From Gross Impact', index=False)
df3.to_excel(writer, sheet_name='Inv To Assumptions', index=False)
df4.to_excel(writer, sheet_name='Inv From Assumptions', index=False)
writer.save() `