Change the button color and height

Hi All,

I have two very simple question, I will appreciate any input from you guys.

  1. Currently, there are 6 button_type. But I would like to change the button color to be, like “orange”. Is there any way to do it?

Some thing like Button(label=‘a’, color=‘orange’)

  1. Another one is how can we define the height of the button. Seems the “height” is not working.

This is a sample code on IPython notebook:

from bokeh.io import show, output_notebook

from bokeh.models import Button

from bokeh.layouts import row, widgetbox, column

output_notebook()

buttons = [Button(label=‘1’, button_type=‘default’, width=100, height=20),

Button(label=‘2’, button_type=‘default’, width=200, height=20),

Button(label=‘3’, button_type=‘default’, width=100, height=50)]

show(column(buttons))

“width” is working, but “height” not.

Thank you very much.

Best,

Xingfeng

Hi Xingfeng, I do not know if there is a way to accomplish this inline with Python, but there is a workaround by editing the styling of your HTML output.

When you call output_file() on your figure, you’ll get an HTML document that imports stylesheets from cdn.pydata.org/bokeh. This is where the green, generic button styling is coming from. You have to override this styling below these stylesheet calls to have an effect. I’ve pulled the section out of a , where I have added CSS styling to the button to make it appear maroon and larger. You can edit padding and colors to accomplish the look you are after.

Bokeh Plot html { width: 100%; height: 100%; } body { width: 90%; height: 100%; margin: auto; } .bk-root .bk-bs-btn-success, .bk-root .bk-bs-btn-success:hover, .bk-root .bk-bs-btn-success:focus, .bk-root .bk-bs-btn-success:active, .bk-root .bk-bs-btn-success.bk-bs-active, .bk-bs-open .bk-bs-dropdown-toggle.bk-root .bk-bs-btn-success { color: #fff; background-color: #9e0142; border-color: #9e0142; padding: 30px 59px; }
···

On Wednesday, January 24, 2018 at 7:58:45 PM UTC-6, Xingfeng wrote:

Hi All,

I have two very simple question, I will appreciate any input from you guys.

  1. Currently, there are 6 button_type. But I would like to change the button color to be, like “orange”. Is there any way to do it?

Some thing like Button(label=‘a’, color=‘orange’)

  1. Another one is how can we define the height of the button. Seems the “height” is not working.

This is a sample code on IPython notebook:

from bokeh.io import show, output_notebook

from bokeh.models import Button

from bokeh.layouts import row, widgetbox, column

output_notebook()

buttons = [Button(label=‘1’, button_type=‘default’, width=100, height=20),

Button(label=‘2’, button_type=‘default’, width=200, height=20),

Button(label=‘3’, button_type=‘default’, width=100, height=50)]

show(column(buttons))

“width” is working, but “height” not.

Thank you very much.

Best,

Xingfeng

Hi, Paige,

Thank you very much for your detailed answer.

One more question, how can I override the stylesheet? I am using bokeh server. I am not sure how should I integrate this style html to my code. Thank you very much.

Best,

Xingfeng

···

On Jan 25, 2018, at 7:46 PM, Paige McKenzie [email protected] wrote:

Hi Xingfeng, I do not know if there is a way to accomplish this inline with Python, but there is a workaround by editing the styling of your HTML output.

When you call output_file() on your figure, you’ll get an HTML document that imports stylesheets from cdn.pydata.org/bokeh. This is where the green, generic button styling is coming from. You have to override this styling below these stylesheet calls to have an effect. I’ve pulled the section out of a , where I have added CSS styling to the button to make it appear maroon and larger. You can edit padding and colors to accomplish the look you are after.

Bokeh Plot

html {

width: 100%;

height: 100%;

}

body {

width: 90%;

height: 100%;

margin: auto;

}

    .bk-root .bk-bs-btn-success, .bk-root .bk-bs-btn-success:hover, .bk-root .bk-bs-btn-success:focus, .bk-root .bk-bs-btn-success:active, .bk-root .bk-bs-btn-success.bk-bs-active, .bk-bs-open .bk-bs-dropdown-toggle.bk-root .bk-bs-btn-success {

color: #fff;

background-color: #9e0142;

border-color: #9e0142;

padding: 30px 59px;

}

On Wednesday, January 24, 2018 at 7:58:45 PM UTC-6, Xingfeng wrote:

Hi All,

I have two very simple question, I will appreciate any input from you guys.

  1. Currently, there are 6 button_type. But I would like to change the button color to be, like “orange”. Is there any way to do it?

Some thing like Button(label=‘a’, color=‘orange’)

  1. Another one is how can we define the height of the button. Seems the “height” is not working.

This is a sample code on IPython notebook:

from bokeh.io import show, output_notebook

from bokeh.models import Button

from bokeh.layouts import row, widgetbox, column

output_notebook()

buttons = [Button(label=‘1’, button_type=‘default’, width=100, height=20),

Button(label=‘2’, button_type=‘default’, width=200, height=20),

Button(label=‘3’, button_type=‘default’, width=100, height=50)]

show(column(buttons))

“width” is working, but “height” not.

Thank you very much.

Best,

Xingfeng


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/f40c7876-eb18-4109-abf1-974dd97f9689%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Here is an example of how to use custom css with the bokeh server, here i show two buttons with different styles.

In the folder “myapp”

myapp/main.py

from bokeh.io import curdoc

from bokeh.models import Button

button_1 = Button(label=“custom button 1”,css_classes=[‘custom_button_1’])

button_2 = Button(label=“custom button 2”,css_classes=[‘custom_button_2’])

curdoc().add_root(button_1)

curdoc().add_root(button_2)

``

myapp/templates/index.html

{{ bokeh_css }}

{{ bokeh_js }}

{% include 'styles.css' %}

{{ plot_div|indent(8) }}

{{ plot_script|indent(8) }}

``

myapp/templates/styles.css:

.custom_button_1 {

width: 500px;

}

.custom_button_1 button.bk-bs-btn.bk-bs-btn-default {

background-color: lightblue;

font-weight: bold;

color:navy;

border-style:solid;

border-width: 10px;

border-color:navy;

height: 300px;

}

.custom_button_2 {

width: 200px;

}

.custom_button_2 button.bk-bs-btn.bk-bs-btn-default{

border:none;

background-color:orange;

height: 80px;

}

``

Not sure why you need to adjust the height for the button itself and the width for the container div, but this works.

Cool!! It works. Thank you very much. Sebastien.

Maybe it will be helpful to add such descriptions to the official website.

···

On Jan 26, 2018, at 11:23 AM, Sébastien Roche [email protected] wrote:

Here is an example of how to use custom css with the bokeh server, here i show two buttons with different styles.

In the folder “myapp”

myapp/main.py

from bokeh.io import curdoc

from bokeh.models import Button

button_1 = Button(label=“custom button 1”,css_classes=[‘custom_button_1’])

button_2 = Button(label=“custom button 2”,css_classes=[‘custom_button_2’])

curdoc().add_root(button_1)

curdoc().add_root(button_2)

``

myapp/templates/index.html

{{ bokeh_css }}

{{ bokeh_js }}

{% include 'styles.css' %}

{{ plot_div|indent(8) }}

{{ plot_script|indent(8) }}

``

myapp/templates/styles.css:

.custom_button_1 {

width: 500px;

}

.custom_button_1 button.bk-bs-btn.bk-bs-btn-default {

background-color: lightblue;

font-weight: bold;

color:navy;

border-style:solid;

border-width: 10px;

border-color:navy;

height: 300px;

}

.custom_button_2 {

width: 200px;

}

.custom_button_2 button.bk-bs-btn.bk-bs-btn-default{

border:none;

background-color:orange;

height: 80px;

}

``

Not sure why you need to adjust the height for the button itself and the width for the container div, but this works.

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/89a13719-0f31-49b2-b5c8-89d9fea9115a%40continuum.io.

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

Hi Sebastien,

Do you know how to adjust the height of CheckBoxGroup. I followed your button example:

myapp/main.py:

from bokeh.io import curdoc

from bokeh.models.widgets import CheckboxGroup

myList = [‘A’, ‘B’, ‘C’,‘D’,‘E’,‘F’,‘G’, ‘H’, ‘I’,‘J’,‘K’,‘L’,‘M’, ‘N’, ‘O’,‘P’,‘Q’,‘R’,‘S’,‘T’,‘U’,‘V’,‘W’, ‘X’, ‘Y’,‘Z’]

chk_group = CheckboxGroup(labels = myList, active=,css_classes=[‘customCheckboxGroup’])

curdoc().clear()

curdoc().add_root(chk_group)

myapp/templates/styles.css:

.customCheckboxGroup {

height: 50px;

}

myapp/templates/index.html:

{{ bokeh_css }}

{{ bokeh_js }}

{% include 'styles.css' %}

{{ plot_div|indent(8) }}

{{ plot_script|indent(8) }}

Any suggestion?

···

On Friday, January 26, 2018 at 11:23:43 AM UTC-8, Sébastien Roche wrote:

Here is an example of how to use custom css with the bokeh server, here i show two buttons with different styles.

In the folder “myapp”

myapp/main.py

from bokeh.io import curdoc

from bokeh.models import Button

button_1 = Button(label=“custom button 1”,css_classes=[‘custom_button_1’])

button_2 = Button(label=“custom button 2”,css_classes=[‘custom_button_2’])

curdoc().add_root(button_1)

curdoc().add_root(button_2)

``

myapp/templates/index.html

{{ bokeh_css }}

{{ bokeh_js }}

{% include 'styles.css' %}

{{ plot_div|indent(8) }}

{{ plot_script|indent(8) }}

``

myapp/templates/styles.css:

.custom_button_1 {

width: 500px;

}

.custom_button_1 button.bk-bs-btn.bk-bs-btn-default {

background-color: lightblue;

font-weight: bold;

color:navy;

border-style:solid;

border-width: 10px;

border-color:navy;

height: 300px;

}

.custom_button_2 {

width: 200px;

}

.custom_button_2 button.bk-bs-btn.bk-bs-btn-default{

border:none;

background-color:orange;

height: 80px;

}

``

Not sure why you need to adjust the height for the button itself and the width for the container div, but this works.