On Feb 19, 2016, at 9:57 AM, Joe <[email protected]> wrote:
Hi,
I have come across this as well and have been meaning to post on it. Here is a minimal example that I think recreates the behavior Robert is describing - i.e it redirects the page from http://localhost:5006/bokeh_button_test to http://localhost:5006/bokeh_button_test? (although it seems that even clicking the button example on the Bokeh user guide has the same effect: Interaction — Bokeh 3.3.2 Documentation)
__
from bokeh.models.widgets import Button
from bokeh.io import curdoc,vform
def button_handler():
print "***you clicked me***"
button = Button(label='Click me', type='primary')
button.on_click(button_handler)
plots = vform(button)
curdoc().add_root(plots)
__
If I run the code, and click the button I get the following output:
bokeh serve --show bokeh_button_test/
DEBUG:bokeh.server.tornado:Allowed Host headers: ['localhost:5006']
DEBUG:bokeh.server.tornado:These host origins can connect to the websocket: ['localhost:5006']
DEBUG:bokeh.server.tornado:Patterns are: [('/bokeh_button_test/?', <class 'bokeh.server.views.doc_handler.DocHandler'>, {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x106a93410>, 'bokeh_websocket_path': '/bokeh_button_test/ws'}), ('/bokeh_button_test/ws', <class 'bokeh.server.views.ws.WSHandler'>, {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x106a93410>, 'bokeh_websocket_path': '/bokeh_button_test/ws'}), ('/bokeh_button_test/autoload.js', <class 'bokeh.server.views.autoload_js_handler.AutoloadJsHandler'>, {'application_context': <bokeh.server.application_context.ApplicationContext object at 0x106a93410>, 'bokeh_websocket_path': '/bokeh_button_test/ws'}), ('/static/(.*)', <class 'bokeh.server.views.static_handler.StaticHandler'>)]
INFO:bokeh.command.subcommands.serve:Starting Bokeh server on port 5006 with applications at paths ['/bokeh_button_test']
INFO:tornado.access:200 GET /bokeh_button_test (::1) 21.19ms
INFO:bokeh.server.views.ws:WebSocket connection opened
DEBUG:bokeh.server.views.ws:Receiver created for Protocol(u'1.0')
DEBUG:bokeh.server.views.ws:ServerHandler created for Protocol(u'1.0')
INFO:bokeh.server.views.ws:ServerConnection created
DEBUG:bokeh.server.session:Sending pull-doc-reply from session 'r4NyMoroxkywM9L4SebVqpFjqfHYG3qu7GerDctD1Th0'
***you clicked me***
INFO:tornado.access:200 GET /bokeh_button_test? (::1) 2.90ms
INFO:bokeh.server.views.ws:WebSocket connection closed: code=None, reason=None
INFO:bokeh.server.views.ws:WebSocket connection opened
DEBUG:bokeh.server.views.ws:Receiver created for Protocol(u'1.0')
DEBUG:bokeh.server.views.ws:ServerHandler created for Protocol(u'1.0')
INFO:bokeh.server.views.ws:ServerConnection created
DEBUG:bokeh.server.session:Sending pull-doc-reply from session 'uPMweprZr8QoOoGuJX1kkdgo3mlXFGF2Zed2TlxtnmKq'
I did some searching on this and found that if I changed the HTML code for the button from:
<button class="bk-bs-btn bk-bs-btn-primary" >Click me</button>
to:
<button class="bk-bs-btn bk-bs-btn-primary" type="button">Click me</button>
Then the button would work as expected and no longer redirects the page:
DEBUG:bokeh.server.tornado:[pid 12774] 1 clients connected
***you clicked me***
DEBUG:bokeh.server.tornado:[pid 12774] 1 clients connected
BUT, HTML coding is outside of my knowledge so I have no idea if this is the correct way to fix this or what other effects this might have. Hopefully this helps though.
If it matters, I'm using a Mac with OSX 10.9 and Safari, but the same problem occurs in Firefox.
Joe
On Friday, February 19, 2016 at 8:25:56 AM UTC-5, Bryan Van de ven wrote:
I have no idea why that should happen (and have never seen anything like that happen). Is it possible to provide a minimal runnable code sample that reproduces this behavior?
Bryan
> On Feb 18, 2016, at 10:08 AM, Robert <[email protected]> wrote:
>
> Hi!
>
> I'm dealing with a strange occurrence where clicking buttons redirects my web browser. The buttons are coded as such:
>
>
> do_integral_button = Button(label = "Calibration Integral")
> save_flexDPE_button = Button(label = "Save file for FlexPDE")
>
> do_integral_button.on_click(lambda identity = self.attribute_ids[i], radio = radio_group, x_box = text_input_xval_integral, y_box = text_input_yval_integral: self.integrate(identity, radio, x_box, y_box))
>
> save_flexDPE_button.on_click(lambda identity = self.attribute_ids[i], radio = radio_group: self.write_to_flexPDE(identity, radio))
>
>
> The lambda structures are to capture context when setting callbacks in a loop.
> And the callbacks are coded like this.
>
> def integrate(self, attrname, radio, x_box, y_box):
>
> element = radio.labels[radio.active]
> source_local = getattr(self, attrname+"_"+element+"_source")
>
> lower_xlim = float(x_box.value)
> lower_ylim = float(y_box.value)
>
> x = np.array(source_local.data["x"])
> y = np.array(source_local.data["y"])
>
> x_change = x[x>lower_xlim]
> y_change = y[len(y)-len(x_change):]
>
> integral = np.trapz(y_change, x = x_change)
>
> print(integral)
>
> def write_to_flexPDE(self, attrname, radio):
> element = radio.labels[radio.active]
>
> source_local = getattr(self, attrname+"_"+element+"_source") #attr_id+"_"+dataset["sample element"]+"_source"
>
> x = np.array(source_local.data["x"])
> y = np.array(source_local.data["y"])
>
> path_to_direct = os.getcwd()
> path_to_flex = path_to_direct + "/data_files/FlexPDE/"
> write_to_filename = path_to_flex+attrname+ "_"+element+".txt"
>
> file_object = open(write_to_filename, "w+")
>
> file_object.write("X %i \n" %len(x))
>
> for item in x:
> file_object.write("%1.3f " %item)
>
> file_object.write("\nData {u} \n")
>
> for item in y:
> file_object.write("%1.1e " %item)
>
> file_object.close()
>
>
> When I click the buttons in the browser the "Save file for FlexPDE" button redirects to what seems to be the address of the active item of the radio group:
> http://localhost:5006/?RadioGroup-0595A745D07443EA9CBA83A56CC91910=0
>
> And the other button, labeled Calibration Integral redirects to:
> http://localhost:5006/?
>
> So I'm wondering what kind of weird instance I've set up for myself.
>
>
> With sincere thanks,
> Robert
>
> --
> 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/a8e5b410-3ec7-4fa0-b4e5-c6b52f2dd40a%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/b8483f40-7dcc-4727-b3ae-7f6ada21eaf0%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.