0

I have a Bokeh directory format like below.

BTSapp.py is my equivalent of 'main.py'

In data folder, I have 1 input (excel) file and 1 output (excel) file. I wrote a script to transform the data from the input file and write it to the output file. I would like to create a bokeh button, which when the end users click they can download the output file.

Can someone please help me? I found this question also on stackoverflow: send file from server to client on bokeh but I couldn't make it work in my case. I kept getting syntax error for JScode_xhr.

Thank you in advance.

Directory format

Étienne
  • 13
  • 5

1 Answers1

0

I tried myself and below is the correct code. It will also fix the issue of double alert and of the generation of 2 excel files after the js code is activated. Note: this is an adjusted version from this post

JScode_fetch = """
var filename = 'my_BSS_result.xlsx';

fetch('/app/static/output.xlsx', {cache: "no-store"}).then(response => response.blob())
                .then(blob => {
                    //addresses IE
                    if (navigator.msSaveBlob) {
                        navigator.msSaveBlob(blob, filename);
                    }

                    else {
                        var link = document.createElement("a");
                        link.href = URL.createObjectURL(blob);
                        
                        link.download = filename;
                        link.target = "_blank";
                        link.style.visibility = 'hidden';
                        link.dispatchEvent(new MouseEvent('click'))
                        URL.revokeObjectURL(url);
                    }
                    return response.text();
                });

"""

Étienne
  • 13
  • 5