dbc.Input in multiple callbacks issue


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
    Output('download', 'data'),
    Input('download', 'n_clicks'),
    Input('netimpacts', '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() `


Does your export callback function have no return statement or you just didn’t paste it? Besides, does it raise any errors in debug mode?

@kw1234, What is the purpose of the output_text function? All the return values titleoutput to titleoutput4 seem to be unused.
As @jlfsjunior pointed out, you define an Output ("download, “data”) for the export function, but it has no return value. Could it be, that this crashes your app? Just remove the Output (“download”, “data”) from the callback I would say.

It raises no errors and downloads a file to disc

When I remove the output, no file is returned. the title output valeus are used to return the value to different pages of my app.

From the component documentation, it expects that data is a dictionary with some information about the file to be downloaded. Your callback seems to be saving the file in the disc, but not prompting the download on the client, which is not how the Download component is intended to be used (imagine that the server is not your local machine…).

Could you try to return dcc.send_file("path_to_xslx") in the callback to see if it fixes your problem? This is what is done in the last example in the component docs that I mentioned above.

@kw1234 ,
You said that “…app calcs stop working…” and “…will only work again after changing the dbc.Input…”. Could you share with us the callback that preforms your calcs? If we can see that, then we might better understand the issue you are facing.