Can't Add Image to Bokeh Application

I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?

from bokeh.plotting import *

IM_HEIGHT = 348

IM_WIDTH = 1148

def create_image_fig():

‘’’

‘’’

IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),

plot_width = IM_WIDTH, plot_height = IM_HEIGHT)

IM_FIG.image_url(url=[‘file:///Users/pjgalliani/Code/vitals/pit/test_image.png’],

x=0, y=342, w=1148, h=342)

IM_FIG.toolbar_location = None

IM_FIG.xaxis.visible = None

IM_FIG.yaxis.visible = None

IM_FIG.outline_line_color = None

---------------------------

curdoc().add_root(IM_FIG)

^^^ Shows no image! ^^^

---------------------------

output_file(“test_image.html”)

show(IM_FIG)

^^^ Works as expected ^^^

create_image_fig()

I believe this is a bug.

Bryan

···

On Mar 8, 2016, at 5:39 PM, Ricky Galliani <[email protected]> wrote:

I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?

from bokeh.plotting import *

IM_HEIGHT = 348
IM_WIDTH = 1148

def create_image_fig():
    '''
    '''
    IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),
                    plot_width = IM_WIDTH, plot_height = IM_HEIGHT)
    IM_FIG.image_url(url=['file:///Users/pjgalliani/Code/vitals/pit/test_image.png'],
                     x=0, y=342, w=1148, h=342)
    IM_FIG.toolbar_location = None
    IM_FIG.xaxis.visible = None
    IM_FIG.yaxis.visible = None
    IM_FIG.outline_line_color = None

    # ---------------------------
    curdoc().add_root(IM_FIG)
    # ^^^ Shows no image! ^^^

    # ---------------------------
    # output_file("test_image.html")
    # show(IM_FIG)
    # ^^^ Works as expected ^^^

create_image_fig()

--
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/65f42590-056a-4124-a483-3e71b81389be%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Do you know of any possible workarounds that I can use until the bug is resolved?

···

On Tuesday, March 8, 2016 at 5:03:12 PM UTC-8, Bryan Van de ven wrote:

I believe this is a bug.

Bryan

On Mar 8, 2016, at 5:39 PM, Ricky Galliani [email protected] wrote:

I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?

from bokeh.plotting import *

IM_HEIGHT = 348

IM_WIDTH = 1148

def create_image_fig():

'''
'''
IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),
                plot_width = IM_WIDTH, plot_height = IM_HEIGHT)
IM_FIG.image_url(url=['file:///Users/pjgalliani/Code/vitals/pit/test_image.png'],
                 x=0, y=342, w=1148, h=342)
IM_FIG.toolbar_location = None
IM_FIG.xaxis.visible = None
IM_FIG.yaxis.visible = None
IM_FIG.outline_line_color = None
# ---------------------------
curdoc().add_root(IM_FIG)
# ^^^ Shows no image! ^^^
# ---------------------------
# output_file("test_image.html")
# show(IM_FIG)
# ^^^ Works as expected ^^^

create_image_fig()


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/65f42590-056a-4124-a483-3e71b81389be%40continuum.io.

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

I'm not aware of anything offhand, unfortunately. I will do my best to try and look at this problem this week.

Bryan

···

On Mar 8, 2016, at 7:04 PM, Ricky Galliani <[email protected]> wrote:

Do you know of any possible workarounds that I can use until the bug is resolved?

On Tuesday, March 8, 2016 at 5:03:12 PM UTC-8, Bryan Van de ven wrote:
I believe this is a bug.

Bryan

> On Mar 8, 2016, at 5:39 PM, Ricky Galliani <[email protected]> wrote:
>
> I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?
>
> from bokeh.plotting import *
>
> IM_HEIGHT = 348
> IM_WIDTH = 1148
>
> def create_image_fig():
> '''
> '''
> IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),
> plot_width = IM_WIDTH, plot_height = IM_HEIGHT)
> IM_FIG.image_url(url=['file:///Users/pjgalliani/Code/vitals/pit/test_image.png'],
> x=0, y=342, w=1148, h=342)
> IM_FIG.toolbar_location = None
> IM_FIG.xaxis.visible = None
> IM_FIG.yaxis.visible = None
> IM_FIG.outline_line_color = None
>
> # ---------------------------
> curdoc().add_root(IM_FIG)
> # ^^^ Shows no image! ^^^
>
> # ---------------------------
> # output_file("test_image.html")
> # show(IM_FIG)
> # ^^^ Works as expected ^^^
>
> create_image_fig()
>
>
> --
> 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/65f42590-056a-4124-a483-3e71b81389be%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/b737c886-a0b9-450a-88d7-64db9255ad1d%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Ricky,

As a workaround, you can start an http-server from the directory that your images are in and then set the image url to be something like ‘http://127.0.0.1:8080/my_image.png’!

Best,

Claire

···

On Tuesday, March 8, 2016 at 5:04:22 PM UTC-8, Ricky Galliani wrote:

Do you know of any possible workarounds that I can use until the bug is resolved?

On Tuesday, March 8, 2016 at 5:03:12 PM UTC-8, Bryan Van de ven wrote:

I believe this is a bug.

Bryan

On Mar 8, 2016, at 5:39 PM, Ricky Galliani [email protected] wrote:

I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?

from bokeh.plotting import *

IM_HEIGHT = 348

IM_WIDTH = 1148

def create_image_fig():

'''
'''
IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),
                plot_width = IM_WIDTH, plot_height = IM_HEIGHT)
IM_FIG.image_url(url=['file:///Users/pjgalliani/Code/vitals/pit/test_image.png'],
                 x=0, y=342, w=1148, h=342)
IM_FIG.toolbar_location = None
IM_FIG.xaxis.visible = None
IM_FIG.yaxis.visible = None
IM_FIG.outline_line_color = None
# ---------------------------
curdoc().add_root(IM_FIG)
# ^^^ Shows no image! ^^^
# ---------------------------
# output_file("test_image.html")
# show(IM_FIG)
# ^^^ Works as expected ^^^

create_image_fig()


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/65f42590-056a-4124-a483-3e71b81389be%40continuum.io.

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

Oh! I did not notice you are using "image_url", instead of "image". The images for "image_url" need to be accessible to the *browser*, i.e. they need to be on some accessible server with an HTTP URL, as Claire correctly notes.

Bryan

···

On Mar 8, 2016, at 9:24 PM, [email protected] wrote:

Hi Ricky,

As a workaround, you can start an http-server from the directory that your images are in and then set the image url to be something like 'http://127.0.0.1:8080/my_image.png&#39;\!

Best,
Claire

On Tuesday, March 8, 2016 at 5:04:22 PM UTC-8, Ricky Galliani wrote:
Do you know of any possible workarounds that I can use until the bug is resolved?

On Tuesday, March 8, 2016 at 5:03:12 PM UTC-8, Bryan Van de ven wrote:
I believe this is a bug.

Bryan

> On Mar 8, 2016, at 5:39 PM, Ricky Galliani <[email protected]> wrote:
>
> I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?
>
> from bokeh.plotting import *
>
> IM_HEIGHT = 348
> IM_WIDTH = 1148
>
> def create_image_fig():
> '''
> '''
> IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),
> plot_width = IM_WIDTH, plot_height = IM_HEIGHT)
> IM_FIG.image_url(url=['file:///Users/pjgalliani/Code/vitals/pit/test_image.png'],
> x=0, y=342, w=1148, h=342)
> IM_FIG.toolbar_location = None
> IM_FIG.xaxis.visible = None
> IM_FIG.yaxis.visible = None
> IM_FIG.outline_line_color = None
>
> # ---------------------------
> curdoc().add_root(IM_FIG)
> # ^^^ Shows no image! ^^^
>
> # ---------------------------
> # output_file("test_image.html")
> # show(IM_FIG)
> # ^^^ Works as expected ^^^
>
> create_image_fig()
>
>
> --
> 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/65f42590-056a-4124-a483-3e71b81389be%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/27afc1d1-9970-4898-8d2f-ee209a786a39%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

Is image supposed to be used for images saved an .jpg or .png? I ran into this issue with the image files in the bokeh application too and solved it with the workaround. When I tried to use the pixel data with image, I think it was having trouble because there was too much data? I'm not sure but it seemed much slower than having it load an image file using image url (the time it took for anything to show up in the browser). I think it may have something to do with needing to set up static routes? I know in flask you can specify a static folder to have images in that you could then use in web pages. Maybe tornado is the same? I don't really know anything about tornado though.

Claire

Hi Claire,

No "image" is like more like "imshow", it's for 2d arrays of numbers (e.g. numpy arrays), that you want to turn into RGBA images according to some colormap, in the browser. It's fine for arrays up to a certain size, but given the need to serialize/deserialize JSON there are fundamental limitations. A binary protocol for arrays might help this some but that is a non-trivial undertaking.

Bryan

···

On Mar 8, 2016, at 11:04 PM, Claire Tang <[email protected]> wrote:

Hi Bryan,

Is image supposed to be used for images saved an .jpg or .png? I ran into this issue with the image files in the bokeh application too and solved it with the workaround. When I tried to use the pixel data with image, I think it was having trouble because there was too much data? I'm not sure but it seemed much slower than having it load an image file using image url (the time it took for anything to show up in the browser). I think it may have something to do with needing to set up static routes? I know in flask you can specify a static folder to have images in that you could then use in web pages. Maybe tornado is the same? I don't really know anything about tornado though.

Claire

--
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/d6ff4bde-a4d7-4710-8c51-cca6292e5015%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks, Claire! This workaround worked well!

-Ricky G

···

On Tuesday, March 8, 2016 at 7:24:28 PM UTC-8, Claire Tang wrote:

Hi Ricky,

As a workaround, you can start an http-server from the directory that your images are in and then set the image url to be something like ‘http://127.0.0.1:8080/my_image.png’!

Best,

Claire

On Tuesday, March 8, 2016 at 5:04:22 PM UTC-8, Ricky Galliani wrote:

Do you know of any possible workarounds that I can use until the bug is resolved?

On Tuesday, March 8, 2016 at 5:03:12 PM UTC-8, Bryan Van de ven wrote:

I believe this is a bug.

Bryan

On Mar 8, 2016, at 5:39 PM, Ricky Galliani [email protected] wrote:

I want to use the code below to place an image figure in my Bokeh application. However, while the code works when I just it to place an image in an html file in the browser with show(), it does not work when I add the object to Bokeh Document for my application. Why is this the case?

from bokeh.plotting import *

IM_HEIGHT = 348

IM_WIDTH = 1148

def create_image_fig():

'''
'''
IM_FIG = Figure(x_range = (0, IM_WIDTH), y_range = (0, IM_HEIGHT),
                plot_width = IM_WIDTH, plot_height = IM_HEIGHT)
IM_FIG.image_url(url=['file:///Users/pjgalliani/Code/vitals/pit/test_image.png'],
                 x=0, y=342, w=1148, h=342)
IM_FIG.toolbar_location = None
IM_FIG.xaxis.visible = None
IM_FIG.yaxis.visible = None
IM_FIG.outline_line_color = None
# ---------------------------
curdoc().add_root(IM_FIG)
# ^^^ Shows no image! ^^^
# ---------------------------
# output_file("test_image.html")
# show(IM_FIG)
# ^^^ Works as expected ^^^

create_image_fig()


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/65f42590-056a-4124-a483-3e71b81389be%40continuum.io.

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