Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Raw data download working locally and not online

$
0
0

Hey,

Basically the title. When running locally, the downloaded .xlsx is perfect but once online I get the error Excel cannot open the file “rawdata.xlsx” because the file format or file extension is not valid.

Had to dig around a lot in the different “download raw data” topics to get it working locally, so maybe the error comes from there? Can’t really tell. Seems weird to me that it works perfectly locally but not online.

Here is the code:

# Inside app layout
html.A('Download Data', id='download-link', download="rawdata.xlsx", href="", target="_blank")

# [...]

# Creating the excel file & letting user download it
@app.callback(Output('download-link', 'href'), 
             [Input('memory-output', 'data')])
def update_download_link(data):
    # skipping details of variables used to create the excel file, can add them if required

    strIO = io.BytesIO()
    excel_writer = pd.ExcelWriter(strIO, engine="xlsxwriter")

    for output in list_of_outputs:
      temp = pd.DataFrame(index=np.arange(0,tree__periods+1))
      temp.loc[:,0] = pd.Series(output[0])

      for j in range(1, tree__periods+1):
        temp.loc[:, j] = pd.Series(output[startbis[j]:endbis[j]+1])

      temp.index = np.arange(1, tree__periods+2)
      temp.to_excel(excel_writer, sheet_name=f"{list_of_names[counter]}")
      counter += 1

    excel_writer.save()
    strIO.seek(0)

    media_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    data = base64.b64encode(strIO.read()).decode("utf-8")
    href_data_downloadable = f'data:{media_type};base64,{data}'
    return href_data_downloadable 

If relevant, find here the excels local and online: https://drive.google.com/drive/folders/1STrzzt2QHtUgshutnoTb_iTPovl_VftV?usp=sharing
Local is perfect and online cannot be opened.

Any help would be greatly appreciated, thanks ! :slight_smile:

2 posts - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles