open html content in new browser tab?

Hi,
I’m trying to use Bokeh Server to launch via TapTool a new browser tab with html content (eventually will be xml content)? Basically nothing happens - no errors, no new tab.

I’ve simplified what I’m doing down to the example below. Opening a URL works fine but cannot get the html content displayed? I’ve limited knowledge of JavaScript (one of my reasons for my interest in Bokeh). Basic mistake by me or something more fundamental?

Example modified from here:interaction_open_url.py — Bokeh 1.0.0 documentation

And ideas on the JavaScript part mainly from here: javascript - Can I open a new window and populate it with a string variable? - Stack Overflow

Thanks in advance,

Dave

from bokeh.server.server import Server
from bokeh.models import CustomJS, ColumnDataSource, TapTool
from bokeh.plotting import figure

html_content = """
<HTML>
<HEAD>
<TITLE>Your Title Here</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM"> </CENTER>
<HR>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<H1>This is a Header</H1>
<H2>This is a Medium Header</H2>
Send me mail at <a href="mailto:[email protected]">
[email protected]</a>.
<P> This is a new paragraph!
<P> <B>This is a new paragraph!</B>
<BR> <B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>
<HR>
</BODY>
</HTML>
"""

def modify_doc(doc):
    p = figure(plot_width=400, plot_height=400, title="Click the Dots")

    source = ColumnDataSource(data=dict(
        x=[1, 2, 3, 4, 5],
        y=[2, 5, 8, 2, 7],
        color=["navy", "orange", "olive", "firebrick", "gold"]
    ))

    p.circle('x', 'y', color='color', size=20, source=source)

    tap_tool = TapTool()
    tap_tool.behavior = 'select'

    # This works fine.
    # js_code = """
    # window.open("http://www.bbc.com");
    # """

    # Does not work - no new tab.
    js_code = """
        var wnd = window.open("about:blank", "", "_blank")
        wnd.document.write({0})
    """.format(html_content)

    # Does not work - no new tab.
    # js_code = """
    # window.open("data:text/html;charset=utf-8,"+{0}, "", "_blank")
    # """.format(html_content)

    # Does not work - no new tab.
    # js_code = """
    # var wnd = window.open("data:text/html;charset=utf-8,", "", "_blank");
    # wnd.document.write({0});
    # wnd.document.close();
    # """.format(html_content)

    tap_tool.callback = CustomJS(code=js_code)
    p.add_tools(tap_tool)

    # Add the tabs in the current document for display
    doc.add_root(p)

# Setting num_procs here means we can't touch the IOLoop before now, we must
# let Server handle that. If you need to explicitly handle IOLoops then you
# will need to use the lower level BaseServer class.
server = Server({'/': modify_doc},
                num_procs=1) # note: on Windows more than one process not supported

if __name__ == '__main__':

    server.io_loop.add_callback(server.show, "/")
    server.io_loop.start()


Hi,

I'm not sure offhand, though I can relate to JavaScript frustrations. However, I do know the Bokeh "save" tool opens up a new window with a Data URL. You can see how the save tool accomplishes that, here:

Thanks,

Bryan

···

On Oct 25, 2018, at 05:40, [email protected] wrote:

Hi,
I'm trying to use Bokeh Server to launch via TapTool a new browser tab with html content (eventually will be xml content)? Basically nothing happens - no errors, no new tab.

I've simplified what I'm doing down to the example below. Opening a URL works fine but cannot get the html content displayed? I've limited knowledge of JavaScript (one of my reasons for my interest in Bokeh). Basic mistake by me or something more fundamental?

Example modified from here:interaction_open_url.py — Bokeh 1.0.0 documentation

And ideas on the JavaScript part mainly from here: javascript - Can I open a new window and populate it with a string variable? - Stack Overflow

Thanks in advance,
Dave

from bokeh.server.server import Server
from bokeh.models import CustomJS, ColumnDataSource, TapTool
from bokeh.plotting import figure

html_content = """
<HTML>
<HEAD>
<TITLE>Your Title Here</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM"> </CENTER>
<HR>
<a href="http://somegreatsite.com">Link Name</a>
is a link to another nifty site
<H1>This is a Header</H1>
<H2>This is a Medium Header</H2>
Send me mail at <a href="mailto:[email protected]">
[email protected]</a>.
<P> This is a new paragraph!
<P> <B>This is a new paragraph!</B>
<BR> <B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>
<HR>
</BODY>
</HTML>
"""

def modify_doc(doc):
    p = figure(plot_width=400, plot_height=400, title="Click the Dots")

    source = ColumnDataSource(data=dict(
        x=[1, 2, 3, 4, 5],
        y=[2, 5, 8, 2, 7],
        color=["navy", "orange", "olive", "firebrick", "gold"]
    ))

    p.circle('x', 'y', color='color', size=20, source=source)

    tap_tool = TapTool()
    tap_tool.behavior = 'select'

    # This works fine.
    # js_code = """
    # window.open("http://www.bbc.com");
    # """

    # Does not work - no new tab.
    js_code = """
        var wnd = window.open("about:blank", "", "_blank")
        wnd.document.write({0})
    """.format(html_content)

    # Does not work - no new tab.
    # js_code = """
    # window.open("data:text/html;charset=utf-8,"+{0}, "", "_blank")
    # """.format(html_content)

    # Does not work - no new tab.
    # js_code = """
    # var wnd = window.open("data:text/html;charset=utf-8,", "", "_blank");
    # wnd.document.write({0});
    # wnd.document.close();
    # """.format(html_content)

    tap_tool.callback = CustomJS(code=js_code)
    p.add_tools(tap_tool)

    # Add the tabs in the current document for display
    doc.add_root(p)

# Setting num_procs here means we can't touch the IOLoop before now, we must
# let Server handle that. If you need to explicitly handle IOLoops then you
# will need to use the lower level BaseServer class.
server = Server({'/': modify_doc},
                num_procs=1) # note: on Windows more than one process not supported

if __name__ == '__main__':

    server.io_loop.add_callback(server.show, "/")
    server.io_loop.start()

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0dbf1364-60cf-47aa-a004-0574cc4b6598%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the reply,
Not quite sure I follow - for me the save tool just opens a dialog box to select where I want the png to go. i.e. no new browser tab/window? Maybe you mean the ‘svg’ part of the switch? I’ll try and figure out what that JavaScript code is doing. But I’d like to be sure that does something close to what I want? :wink:

Regards,

Dave

···

On Thursday, October 25, 2018 at 5:32:56 PM UTC+2, Bryan Van de ven wrote:

Hi,

I’m not sure offhand, though I can relate to JavaScript frustrations. However, I do know the Bokeh “save” tool opens up a new window with a Data URL. You can see how the save tool accomplishes that, here:

https://github.com/bokeh/bokeh/blob/ac92b9f8c8f498e2b22cc51ae5179a2f13d3a2b6/bokehjs/src/lib/models/plots/plot_canvas.ts#L935-L968

Thanks,

Bryan

On Oct 25, 2018, at 05:40, [email protected] wrote:

Hi,

I’m trying to use Bokeh Server to launch via TapTool a new browser tab with html content (eventually will be xml content)? Basically nothing happens - no errors, no new tab.

I’ve simplified what I’m doing down to the example below. Opening a URL works fine but cannot get the html content displayed? I’ve limited knowledge of JavaScript (one of my reasons for my interest in Bokeh). Basic mistake by me or something more fundamental?

Example modified from here:interaction_open_url.py — Bokeh 1.0.0 documentation

And ideas on the JavaScript part mainly from here: javascript - Can I open a new window and populate it with a string variable? - Stack Overflow

Thanks in advance,

Dave

from bokeh.server.server import Server

from bokeh.models import CustomJS, ColumnDataSource, TapTool

from bokeh.plotting import figure

html_content = “”"

Your Title Here

Link Name

is a link to another nifty site

This is a Header

This is a Medium Header

Send me mail at

sup…@yourcompany.com.

This is a new paragraph!

This is a new paragraph!


This is a new sentence without a paragraph break, in bold italics.


“”"

def modify_doc(doc):

p = figure(plot_width=400, plot_height=400, title="Click the Dots")
source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    color=["navy", "orange", "olive", "firebrick", "gold"]
))
p.circle('x', 'y', color='color', size=20, source=source)
tap_tool = TapTool()
tap_tool.behavior = 'select'
# This works fine.
# js_code = """
#        window.open("[http://www.bbc.com](http://www.bbc.com)");
# """
# Does not work - no new tab.
js_code = """
    var wnd = window.open("about:blank", "", "_blank")
    wnd.document.write({0})
""".format(html_content)
# Does not work - no new tab.
# js_code = """
#    window.open("data:text/html;charset=utf-8,"+{0}, "", "_blank")
# """.format(html_content)
# Does not work - no new tab.
# js_code = """
#     var wnd = window.open("data:text/html;charset=utf-8,", "", "_blank");
#     wnd.document.write({0});
#     wnd.document.close();
# """.format(html_content)
tap_tool.callback = CustomJS(code=js_code)
p.add_tools(tap_tool)
# Add the tabs in the current document for display
doc.add_root(p)

Setting num_procs here means we can’t touch the IOLoop before now, we must

let Server handle that. If you need to explicitly handle IOLoops then you

will need to use the lower level BaseServer class.

server = Server({‘/’: modify_doc},

            num_procs=1)  # note: on Windows more than one process not supported

if name == ‘main’:

server.io_loop.add_callback(server.show, "/")
server.io_loop.start()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0dbf1364-60cf-47aa-a004-0574cc4b6598%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Well, I guess that's another thing to mention -- the same JS code often does different things on different browsers. On OSX/Safari, activating the save tool opens the content in a new tab. Unfortunately dealing with browser inconsistencies is an unavoidable fact of web development. For things that are in project scope, Bokeh obviously tries to do that work, but it's not clear to me that defined functionality for creating and opening data URLs is within scope.

Since it looks like you are starting a Bokeh server programmatically, it might be simpler to just add a new request handler directly to the Bokeh Tornado app that serves the output you want in the new tab. Then it's possible that "window.open" with the URL for that endpoint will work as expected (untested, but my sense is that window.open only works with "regular" URLs).

Thanks,

Bryan

···

On Oct 25, 2018, at 09:10, [email protected] wrote:

Thanks for the reply,
Not quite sure I follow - for me the save tool just opens a dialog box to select where I want the png to go. i.e. no new browser tab/window? Maybe you mean the 'svg' part of the switch? I'll try and figure out what that JavaScript code is doing. But I'd like to be sure that does something close to what I want? :wink:

Regards,
Dave

On Thursday, October 25, 2018 at 5:32:56 PM UTC+2, Bryan Van de ven wrote:
Hi,

I'm not sure offhand, though I can relate to JavaScript frustrations. However, I do know the Bokeh "save" tool opens up a new window with a Data URL. You can see how the save tool accomplishes that, here:

https://github.com/bokeh/bokeh/blob/ac92b9f8c8f498e2b22cc51ae5179a2f13d3a2b6/bokehjs/src/lib/models/plots/plot_canvas.ts#L935-L968

Thanks,

Bryan

> On Oct 25, 2018, at 05:40, dave.k...@gmail.com wrote:
>
> Hi,
> I'm trying to use Bokeh Server to launch via TapTool a new browser tab with html content (eventually will be xml content)? Basically nothing happens - no errors, no new tab.
>
> I've simplified what I'm doing down to the example below. Opening a URL works fine but cannot get the html content displayed? I've limited knowledge of JavaScript (one of my reasons for my interest in Bokeh). Basic mistake by me or something more fundamental?
>
> Example modified from here:interaction_open_url.py — Bokeh 1.0.0 documentation
>
> And ideas on the JavaScript part mainly from here: javascript - Can I open a new window and populate it with a string variable? - Stack Overflow
>
> Thanks in advance,
> Dave
>
> from bokeh.server.server import Server
> from bokeh.models import CustomJS, ColumnDataSource, TapTool
> from bokeh.plotting import figure
>
> html_content = """
> <HTML>
> <HEAD>
> <TITLE>Your Title Here</TITLE>
> </HEAD>
> <BODY BGCOLOR="FFFFFF">
> <CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM"> </CENTER>
> <HR>
> <a href="http://somegreatsite.com">Link Name</a>
> is a link to another nifty site
> <H1>This is a Header</H1>
> <H2>This is a Medium Header</H2>
> Send me mail at <a href="mailto:sup...@yourcompany.com">
> [email protected]</a>.
> <P> This is a new paragraph!
> <P> <B>This is a new paragraph!</B>
> <BR> <B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>
> <HR>
> </BODY>
> </HTML>
> """
>
>
> def modify_doc(doc):
> p = figure(plot_width=400, plot_height=400, title="Click the Dots")
>
> source = ColumnDataSource(data=dict(
> x=[1, 2, 3, 4, 5],
> y=[2, 5, 8, 2, 7],
> color=["navy", "orange", "olive", "firebrick", "gold"]
> ))
>
> p.circle('x', 'y', color='color', size=20, source=source)
>
> tap_tool = TapTool()
> tap_tool.behavior = 'select'
>
> # This works fine.
> # js_code = """
> # window.open("http://www.bbc.com");
> # """
>
> # Does not work - no new tab.
> js_code = """
> var wnd = window.open("about:blank", "", "_blank")
> wnd.document.write({0})
> """.format(html_content)
>
> # Does not work - no new tab.
> # js_code = """
> # window.open("data:text/html;charset=utf-8,"+{0}, "", "_blank")
> # """.format(html_content)
>
> # Does not work - no new tab.
> # js_code = """
> # var wnd = window.open("data:text/html;charset=utf-8,", "", "_blank");
> # wnd.document.write({0});
> # wnd.document.close();
> # """.format(html_content)
>
> tap_tool.callback = CustomJS(code=js_code)
> p.add_tools(tap_tool)
>
> # Add the tabs in the current document for display
> doc.add_root(p)
>
>
> # Setting num_procs here means we can't touch the IOLoop before now, we must
> # let Server handle that. If you need to explicitly handle IOLoops then you
> # will need to use the lower level BaseServer class.
> server = Server({'/': modify_doc},
> num_procs=1) # note: on Windows more than one process not supported
>
> if __name__ == '__main__':
>
> server.io_loop.add_callback(server.show, "/")
> server.io_loop.start()
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0dbf1364-60cf-47aa-a004-0574cc4b6598%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4cc183b2-e19d-41a8-9a90-f67adeb40e8d%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the reply,
Point taken regarding the differences between browsers (in my case Win10 and Chrome). And I also take your point about what is part of Bokeh and what is not…

I’ll follow up on your suggestion below (I came across a similar suggestion elsewhere - Tornado StaticFileHandler). But first I need to look generally at what I need w.r.t. servers / frameworks… I.e. Tornado, or Flask, or Pyramid, or Django, or … I assume Bokeh can in principle be used with any of these? I saw some examples you put up on github (bokeh/examples/howto/server_embed at 0.13.0 · bokeh/bokeh). Will be a while before I get back to this… But I’ll post here if I figure out anything that might be of use to others…

Regards,

···

On Thursday, October 25, 2018 at 11:16:42 PM UTC+2, Bryan Van de ven wrote:

Well, I guess that’s another thing to mention – the same JS code often does different things on different browsers. On OSX/Safari, activating the save tool opens the content in a new tab. Unfortunately dealing with browser inconsistencies is an unavoidable fact of web development. For things that are in project scope, Bokeh obviously tries to do that work, but it’s not clear to me that defined functionality for creating and opening data URLs is within scope.

Since it looks like you are starting a Bokeh server programmatically, it might be simpler to just add a new request handler directly to the Bokeh Tornado app that serves the output you want in the new tab. Then it’s possible that “window.open” with the URL for that endpoint will work as expected (untested, but my sense is that window.open only works with “regular” URLs).

Thanks,

Bryan

On Oct 25, 2018, at 09:10, [email protected] wrote:

Thanks for the reply,

Not quite sure I follow - for me the save tool just opens a dialog box to select where I want the png to go. i.e. no new browser tab/window? Maybe you mean the ‘svg’ part of the switch? I’ll try and figure out what that JavaScript code is doing. But I’d like to be sure that does something close to what I want? :wink:

Regards,

Dave

On Thursday, October 25, 2018 at 5:32:56 PM UTC+2, Bryan Van de ven wrote:

Hi,

I’m not sure offhand, though I can relate to JavaScript frustrations. However, I do know the Bokeh “save” tool opens up a new window with a Data URL. You can see how the save tool accomplishes that, here:

https://github.com/bokeh/bokeh/blob/ac92b9f8c8f498e2b22cc51ae5179a2f13d3a2b6/bokehjs/src/lib/models/plots/plot_canvas.ts#L935-L968

Thanks,

Bryan

On Oct 25, 2018, at 05:40, [email protected] wrote:

Hi,
I’m trying to use Bokeh Server to launch via TapTool a new browser tab with html content (eventually will be xml content)? Basically nothing happens - no errors, no new tab.

I’ve simplified what I’m doing down to the example below. Opening a URL works fine but cannot get the html content displayed? I’ve limited knowledge of JavaScript (one of my reasons for my interest in Bokeh). Basic mistake by me or something more fundamental?

Example modified from here:interaction_open_url.py — Bokeh 1.0.0 documentation

And ideas on the JavaScript part mainly from here: javascript - Can I open a new window and populate it with a string variable? - Stack Overflow

Thanks in advance,
Dave

from bokeh.server.server import Server
from bokeh.models import CustomJS, ColumnDataSource, TapTool
from bokeh.plotting import figure

html_content = “”"

Your Title Here
Link Name is a link to another nifty site

This is a Header

This is a Medium Header

Send me mail at [email protected].

This is a new paragraph!

This is a new paragraph!
This is a new sentence without a paragraph break, in bold italics.


"""

def modify_doc(doc):
p = figure(plot_width=400, plot_height=400, title=“Click the Dots”)

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    color=["navy", "orange", "olive", "firebrick", "gold"]
))

p.circle('x', 'y', color='color', size=20, source=source)

tap_tool = TapTool()
tap_tool.behavior = 'select'

# This works fine.
# js_code = """
#        window.open("[http://www.bbc.com](http://www.bbc.com)");
# """

# Does not work - no new tab.
js_code = """
    var wnd = window.open("about:blank", "", "_blank")
    wnd.document.write({0})
""".format(html_content)

# Does not work - no new tab.
# js_code = """
#    window.open("data:text/html;charset=utf-8,"+{0}, "", "_blank")
# """.format(html_content)

# Does not work - no new tab.
# js_code = """
#     var wnd = window.open("data:text/html;charset=utf-8,", "", "_blank");
#     wnd.document.write({0});
#     wnd.document.close();
# """.format(html_content)

tap_tool.callback = CustomJS(code=js_code)
p.add_tools(tap_tool)

# Add the tabs in the current document for display
doc.add_root(p)

Setting num_procs here means we can’t touch the IOLoop before now, we must

let Server handle that. If you need to explicitly handle IOLoops then you

will need to use the lower level BaseServer class.

server = Server({‘/’: modify_doc},
num_procs=1) # note: on Windows more than one process not supported

if name == ‘main’:

server.io_loop.add_callback(server.show, "/")
server.io_loop.start()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0dbf1364-60cf-47aa-a004-0574cc4b6598%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4cc183b2-e19d-41a8-9a90-f67adeb40e8d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Short follow up for anyone that might be interested. As you pointed out, displaying html moves out of the focus Bokeh. I decided to go with Flask as the web server. After figuring things out, below is the essence of the solution. Basically get the xml content from the database, then create an ‘in memory file’ (BytesIO) of it, then send it back to the browser via Flask ‘send_file’. There are some details along that way: administration to map Bokeh sessions/documents to Flask sessions. But that’s a different story, might be a more elegant way to do it :wink:

Regards,


@app.route('/dynamic_utc')
def serve_dynamic_utc():
    utc_file_name = app.bokeh_interop.get_utc_file_name(session.sid, flask=True)
    if not utc_file_name:
        # TODO??? display error page I guess...
        pass
    f = open(utc_file_name, 'rb')
    buffer = BytesIO()
    buffer.write(f.read())
    buffer.seek(0)
    return send_file(buffer,
                     attachment_filename='dynamic.xml', # extension used to guess the mime type
                     as_attachment=False) # True saves the content to a file via the browser

···

On Sunday, October 28, 2018 at 4:23:18 PM UTC+1, [email protected] wrote:

Thanks for the reply,
Point taken regarding the differences between browsers (in my case Win10 and Chrome). And I also take your point about what is part of Bokeh and what is not…

I’ll follow up on your suggestion below (I came across a similar suggestion elsewhere - Tornado StaticFileHandler). But first I need to look generally at what I need w.r.t. servers / frameworks… I.e. Tornado, or Flask, or Pyramid, or Django, or … I assume Bokeh can in principle be used with any of these? I saw some examples you put up on github (bokeh/examples/howto/server_embed at 0.13.0 · bokeh/bokeh). Will be a while before I get back to this… But I’ll post here if I figure out anything that might be of use to others…

Regards,

On Thursday, October 25, 2018 at 11:16:42 PM UTC+2, Bryan Van de ven wrote:

Well, I guess that’s another thing to mention – the same JS code often does different things on different browsers. On OSX/Safari, activating the save tool opens the content in a new tab. Unfortunately dealing with browser inconsistencies is an unavoidable fact of web development. For things that are in project scope, Bokeh obviously tries to do that work, but it’s not clear to me that defined functionality for creating and opening data URLs is within scope.

Since it looks like you are starting a Bokeh server programmatically, it might be simpler to just add a new request handler directly to the Bokeh Tornado app that serves the output you want in the new tab. Then it’s possible that “window.open” with the URL for that endpoint will work as expected (untested, but my sense is that window.open only works with “regular” URLs).

Thanks,

Bryan

On Oct 25, 2018, at 09:10, [email protected] wrote:

Thanks for the reply,

Not quite sure I follow - for me the save tool just opens a dialog box to select where I want the png to go. i.e. no new browser tab/window? Maybe you mean the ‘svg’ part of the switch? I’ll try and figure out what that JavaScript code is doing. But I’d like to be sure that does something close to what I want? :wink:

Regards,

Dave

On Thursday, October 25, 2018 at 5:32:56 PM UTC+2, Bryan Van de ven wrote:

Hi,

I’m not sure offhand, though I can relate to JavaScript frustrations. However, I do know the Bokeh “save” tool opens up a new window with a Data URL. You can see how the save tool accomplishes that, here:

https://github.com/bokeh/bokeh/blob/ac92b9f8c8f498e2b22cc51ae5179a2f13d3a2b6/bokehjs/src/lib/models/plots/plot_canvas.ts#L935-L968

Thanks,

Bryan

On Oct 25, 2018, at 05:40, [email protected] wrote:

Hi,
I’m trying to use Bokeh Server to launch via TapTool a new browser tab with html content (eventually will be xml content)? Basically nothing happens - no errors, no new tab.

I’ve simplified what I’m doing down to the example below. Opening a URL works fine but cannot get the html content displayed? I’ve limited knowledge of JavaScript (one of my reasons for my interest in Bokeh). Basic mistake by me or something more fundamental?

Example modified from here:interaction_open_url.py — Bokeh 1.0.0 documentation

And ideas on the JavaScript part mainly from here: javascript - Can I open a new window and populate it with a string variable? - Stack Overflow

Thanks in advance,
Dave

from bokeh.server.server import Server
from bokeh.models import CustomJS, ColumnDataSource, TapTool
from bokeh.plotting import figure

html_content = “”"

Your Title Here
Link Name is a link to another nifty site

This is a Header

This is a Medium Header

Send me mail at [email protected].

This is a new paragraph!

This is a new paragraph!
This is a new sentence without a paragraph break, in bold italics.


"""

def modify_doc(doc):
p = figure(plot_width=400, plot_height=400, title=“Click the Dots”)

source = ColumnDataSource(data=dict(
    x=[1, 2, 3, 4, 5],
    y=[2, 5, 8, 2, 7],
    color=["navy", "orange", "olive", "firebrick", "gold"]
))

p.circle('x', 'y', color='color', size=20, source=source)

tap_tool = TapTool()
tap_tool.behavior = 'select'

# This works fine.
# js_code = """
#        window.open("[http://www.bbc.com](http://www.bbc.com)");
# """

# Does not work - no new tab.
js_code = """
    var wnd = window.open("about:blank", "", "_blank")
    wnd.document.write({0})
""".format(html_content)

# Does not work - no new tab.
# js_code = """
#    window.open("data:text/html;charset=utf-8,"+{0}, "", "_blank")
# """.format(html_content)

# Does not work - no new tab.
# js_code = """
#     var wnd = window.open("data:text/html;charset=utf-8,", "", "_blank");
#     wnd.document.write({0});
#     wnd.document.close();
# """.format(html_content)

tap_tool.callback = CustomJS(code=js_code)
p.add_tools(tap_tool)

# Add the tabs in the current document for display
doc.add_root(p)

Setting num_procs here means we can’t touch the IOLoop before now, we must

let Server handle that. If you need to explicitly handle IOLoops then you

will need to use the lower level BaseServer class.

server = Server({‘/’: modify_doc},
num_procs=1) # note: on Windows more than one process not supported

if name == ‘main’:

server.io_loop.add_callback(server.show, "/")
server.io_loop.start()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0dbf1364-60cf-47aa-a004-0574cc4b6598%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/4cc183b2-e19d-41a8-9a90-f67adeb40e8d%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.