CustomJS to open excel file using Button within browser with Bokeh Server

Hi,
if I use this code

···

from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import Figure, show
from bokeh.models.widgets import Button
x = [x*0.005 for x in range(0, 200)]
y = x
nomeFileExcel=“file:/C:/Eclipse/eclipse-workspace/BiDia/src/mauro.xlsx”
source = ColumnDataSource(data=dict(x=x, y=y))
bottoneCallback = CustomJS(args=dict(source=source),
code="""
var A= ‘{0}’;
window.open(A);
“”" .format (str(nomeFileExcel)))

bottone=Button(label=“testo”,button_type=“success”,name=“nome”,callback=bottoneCallback)
layout = column(bottone)
show(layout)

All work very fine

BUT if I try to use the same code with Bokeh Server

from os.path import dirname, join
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import Figure, show
from bokeh.models.widgets import Button
from bokeh.plotting import curdoc
x = [x*0.005 for x in range(0, 200)]
y = x
nomeFileExcel=“file:/C:/Eclipse/eclipse-workspace/BiDia/src/mauro.xlsx”
source = ColumnDataSource(data=dict(x=x, y=y))
bottoneCallback = CustomJS(args=dict(source=source),
code="""
var A= ‘{0}’;
window.open(A);
“”" .format (str(nomeFileExcel)))

bottone=Button(label=“testo”,button_type=“success”,name=“nome”,callback=bottoneCallback)
layout = column(bottone)
curdoc().add_root(layout)

http://localhost:5006/testWindowOpenServe

bokeh serve testWindowOpenServe


The file in not open and the console web tell me this errror:

Error: Access to ‘file:///C:/Eclipse/eclipse-workspace/BiDia/src/mauro.xlsx’ from script denied

In wich way I can do a window.open usinf Bokeh Server?

Kind regards

Mauro

Hi Mauro,

Such access is forbidden because it’s a security concern - otherwise, random websites would be able to just download data from you computer.

You can use the directory format with “bokeh serve”: https://bokeh.pydata.org/en/latest/docs/user_guide/server.html#directory-format

With it, you can make your Excel file available via the webserver itself, so you would access it via URL similar to http://localhost:5006/static/mauro.xlsx

Regards,

Eugene

···

On Tuesday, February 6, 2018 at 4:53:45 AM UTC+7, [email protected] wrote:

Hi,
if I use this code

from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import Figure, show
from bokeh.models.widgets import Button
x = [x*0.005 for x in range(0, 200)]
y = x
nomeFileExcel=“file:/C:/Eclipse/eclipse-workspace/BiDia/src/mauro.xlsx”
source = ColumnDataSource(data=dict(x=x, y=y))
bottoneCallback = CustomJS(args=dict(source=source),
code="""
var A= ‘{0}’;
window.open(A);
“”" .format (str(nomeFileExcel)))

bottone=Button(label=“testo”,button_type=“success”,name=“nome”,callback=bottoneCallback)
layout = column(bottone)
show(layout)

All work very fine

BUT if I try to use the same code with Bokeh Server

from os.path import dirname, join
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource
from bokeh.plotting import Figure, show
from bokeh.models.widgets import Button
from bokeh.plotting import curdoc
x = [x*0.005 for x in range(0, 200)]
y = x
nomeFileExcel=“file:/C:/Eclipse/eclipse-workspace/BiDia/src/mauro.xlsx”
source = ColumnDataSource(data=dict(x=x, y=y))
bottoneCallback = CustomJS(args=dict(source=source),
code="""
var A= ‘{0}’;
window.open(A);
“”" .format (str(nomeFileExcel)))

bottone=Button(label=“testo”,button_type=“success”,name=“nome”,callback=bottoneCallback)
layout = column(bottone)
curdoc().add_root(layout)

http://localhost:5006/testWindowOpenServe

bokeh serve testWindowOpenServe


The file in not open and the console web tell me this errror:

Error: Access to ‘file:///C:/Eclipse/eclipse-workspace/BiDia/src/mauro.xlsx’ from script denied

In wich way I can do a window.open usinf Bokeh Server?

Kind regards

Mauro

Hi Eugene

Hello
thanks for your support.
Excuse me but I could not fully understand your suggestion.

In this folder
C:\Eclipse\eclipse-workspace\BiDia\src\static
exists a file with name mauro.xlsx

I open a cmd session and i do
cd C:\Eclipse\eclipse-workspace\BiDia

then I call Bokeh in this way
bokeh serve testWindowOpenServe.py

If I try to do in the program testWindowsOpenServe.py a
windows.open('http://localhost:5006/testWindowOpenServe/static/mauro.xlsx')
or a
windows.open('http://localhost:5006/testWindowOpenServe/mauro.xlsx)
or a
windows.open('http://localhost:5006/static/mauro.xlsx)

I see allways this error: 404 not found

Where am I doing wrong?
Thanks again for your kindness
Mauro

Hi Mauro,

Sorry for the waiting.

In order for the directory-based layout to work, you have to use “bokeh serve %dir_name%”, where “%dir_name%” is the relative path to the directory that contains “main.py” file.

The app name, in this case, would be the directory name, so the URL would be http://localhost:5006/dir_name/static/mauro.xlsx

Note that you don’t have to specify the absolute URL in “window.open”, you can just write “window.open(‘dir_name/static/mauro.xlsx’)”.

Regards,

Eugene

···

On Wednesday, February 7, 2018 at 5:48:16 AM UTC+7, [email protected] wrote:

Hi Eugene

Hello
thanks for your support.
Excuse me but I could not fully understand your suggestion.

In this folder
C:\Eclipse\eclipse-workspace\BiDia\src\static
exists a file with name mauro.xlsx

I open a cmd session and i do
cd C:\Eclipse\eclipse-workspace\BiDia

then I call Bokeh in this way
bokeh serve testWindowOpenServe.py

If I try to do in the program testWindowsOpenServe.py a
windows.open('[http://localhost:5006/testWindowOpenServe/static/mauro.xlsx](http://localhost:5006/testWindowOpenServe/static/mauro.xlsx)')
or a
windows.open('[http://localhost:5006/testWindowOpenServe/mauro.xlsx](http://localhost:5006/testWindowOpenServe/mauro.xlsx))
or a
windows.open('[http://localhost:5006/static/mauro.xlsx](http://localhost:5006/static/mauro.xlsx))

I see allways this error: 404 not found


Where am I doing wrong?
Thanks again for your kindness
Mauro


Hi there,

it seems to me that only files in the “static” folder are available via the URL. Is that correct?

Thanks!

···

Am Samstag, 10. Februar 2018 22:19:36 UTC+1 schrieb Eugene Pakhomov:

Hi Mauro,

Sorry for the waiting.

In order for the directory-based layout to work, you have to use “bokeh serve %dir_name%”, where “%dir_name%” is the relative path to the directory that contains “main.py” file.

The app name, in this case, would be the directory name, so the URL would be http://localhost:5006/dir_name/static/mauro.xlsx

Note that you don’t have to specify the absolute URL in “window.open”, you can just write “window.open(‘dir_name/static/mauro.xlsx’)”.

Regards,

Eugene

On Wednesday, February 7, 2018 at 5:48:16 AM UTC+7, [email protected] wrote:

Hi Eugene

Hello
thanks for your support.
Excuse me but I could not fully understand your suggestion.

In this folder
C:\Eclipse\eclipse-workspace\BiDia\src\static
exists a file with name mauro.xlsx

I open a cmd session and i do
cd C:\Eclipse\eclipse-workspace\BiDia

then I call Bokeh in this way
bokeh serve testWindowOpenServe.py

If I try to do in the program testWindowsOpenServe.py a
windows.open('[http://localhost:5006/testWindowOpenServe/static/mauro.xlsx](http://localhost:5006/testWindowOpenServe/static/mauro.xlsx)')
or a
windows.open('[http://localhost:5006/testWindowOpenServe/mauro.xlsx](http://localhost:5006/testWindowOpenServe/mauro.xlsx))
or a
windows.open('[http://localhost:5006/static/mauro.xlsx](http://localhost:5006/static/mauro.xlsx))

I see allways this error: 404 not found


Where am I doing wrong?
Thanks again for your kindness
Mauro


That is correct.

  • Eugene
···

On Wednesday, February 14, 2018 at 7:29:09 PM UTC+7, Joris Nettelstroth wrote:

Hi there,

it seems to me that only files in the “static” folder are available via the URL. Is that correct?

Thanks!

Am Samstag, 10. Februar 2018 22:19:36 UTC+1 schrieb Eugene Pakhomov:

Hi Mauro,

Sorry for the waiting.

In order for the directory-based layout to work, you have to use “bokeh serve %dir_name%”, where “%dir_name%” is the relative path to the directory that contains “main.py” file.

The app name, in this case, would be the directory name, so the URL would be http://localhost:5006/dir_name/static/mauro.xlsx

Note that you don’t have to specify the absolute URL in “window.open”, you can just write “window.open(‘dir_name/static/mauro.xlsx’)”.

Regards,

Eugene

On Wednesday, February 7, 2018 at 5:48:16 AM UTC+7, [email protected] wrote:

Hi Eugene

Hello
thanks for your support.
Excuse me but I could not fully understand your suggestion.

In this folder
C:\Eclipse\eclipse-workspace\BiDia\src\static
exists a file with name mauro.xlsx

I open a cmd session and i do
cd C:\Eclipse\eclipse-workspace\BiDia

then I call Bokeh in this way
bokeh serve testWindowOpenServe.py

If I try to do in the program testWindowsOpenServe.py a
windows.open('[http://localhost:5006/testWindowOpenServe/static/mauro.xlsx](http://localhost:5006/testWindowOpenServe/static/mauro.xlsx)')
or a
windows.open('[http://localhost:5006/testWindowOpenServe/mauro.xlsx](http://localhost:5006/testWindowOpenServe/mauro.xlsx))
or a
windows.open('[http://localhost:5006/static/mauro.xlsx](http://localhost:5006/static/mauro.xlsx))

I see allways this error: 404 not found


Where am I doing wrong?
Thanks again for your kindness
Mauro