Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout does not use active_tools options #5119

Open
MarcSkovMadsen opened this issue Nov 9, 2021 · 3 comments
Open

Layout does not use active_tools options #5119

MarcSkovMadsen opened this issue Nov 9, 2021 · 3 comments
Labels
TRIAGE Needs triaging

Comments

@MarcSkovMadsen
Copy link
Collaborator

I'm trying to create a Panel example for scikit-image.

I have two images (before+after). I want them to share the toolbar and have box_zoom as the default active tool.

But I cannot achieve that.

The first two rows below do not have box_zoom as the active_tool even though I've specified it.

The third has box_zoom as the active_tool but does not share the toolbar.

image

import holoviews as hv
import panel as pn
from skimage import data, filters

image = data.coins()
edges = filters.sobel(image)*256

bounds = (-1, -1, 1, 1)

before_img = hv.Image(image, bounds=bounds).apply.opts(
    cmap="binary_r", height=400, width=400, title="Before", active_tools=["box_zoom"], tools=["hover"]
)
after_img = hv.Image(edges, bounds=bounds).apply.opts(
    cmap="binary_r", height=400, width=400, title="After", active_tools=["box_zoom"], tools=["hover"], colorbar=True
)
layout=(before_img+after_img).apply.opts(active_tools=["box_zoom"])

pn.Column(
    pn.panel(before_img+after_img, sizing_mode="fixed"),
    pn.panel(layout, sizing_mode="fixed"),
    pn.Row(before_img, after_img, sizing_mode="fixed"),
).servable()
@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Needs triaging label Nov 9, 2021
@jbednar
Copy link
Member

jbednar commented Nov 9, 2021

I can reproduce that, though I don't know if the problem is in HoloViews or the underlying Bokeh code.

@MarcSkovMadsen
Copy link
Collaborator Author

Just got hit by this again. There is also a user reporting the issue on Discourse: https://discourse.holoviz.org/t/how-to-set-active-tools-for-layout/2006

@MarcSkovMadsen
Copy link
Collaborator Author

Just got hit by this again trying to create a dashboard with crossfiltering for Panel tutorials.

image

import holoviews as hv
import numpy as np
import pandas as pd
import panel as pn
from bokeh.models.formatters import NumeralTickFormatter

pn.extension(sizing_mode="stretch_width")

ACCENT = "teal"

SHORT_NAMES = {
    "Changzhou Railcar Propulsion Engineering Research and Development Center": "Changzhou",
    "Siemens Gamesa Renewable Energy": "Siemens Gamesa",
}

@pn.cache()
def _download_data():
    return pd.read_csv("https://assets.holoviz.org/panel/tutorials/turbines.csv.gz")

@pn.cache
def get_data():
    data = _download_data()
    mask = data.t_manu.isin(list(SHORT_NAMES))
    data.loc[mask, "t_manu"] = data.loc[mask, "t_manu"].map(SHORT_NAMES)
    data.t_cap = data.t_cap/10**6
    return data

# @pn.cache
def plot_with_crossfilter():
    data = get_data()

    # Define shared dataset
    ds = hv.Dataset(data, ["t_manu", "p_year", "t_cap"], "t_cap")
    
    # Create plots
    ds_by_year = ds.aggregate("p_year", function=np.sum).sort("p_year")
    ds_by_manufacturer = ds.aggregate("t_manu", function=np.sum).sort("t_cap", reverse=True)
    formatter = NumeralTickFormatter(format="0,0")
    plot_by_year = hv.Bars(ds_by_year, ("p_year", "Year"), ("t_cap", "Capacity (GW)")).opts(
        responsive=True, xrotation=90, yformatter=formatter, color=ACCENT, tools=["hover"], active_tools=['box_select']
    )
    plot_by_manufacturer = hv.Bars(ds_by_manufacturer, ("t_manu", "Manufacturer"), ("t_cap", "Capacity (GW)")).opts(
        responsive=True, xrotation=90, yformatter=formatter, color=ACCENT, tools=["hover"], active_tools=['box_select']
    )

    # Link plots
    layout = (plot_by_year + plot_by_manufacturer).cols(1)
    selections = hv.link_selections(layout)
    return selections

cross_filter_plot = plot_with_crossfilter()

pn.template.FastListTemplate(
    title="Windturbine Dashboard with Crossfiltering",
    main=[cross_filter_plot],
    main_layout=None,
    accent=ACCENT,
).servable()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TRIAGE Needs triaging
Projects
None yet
Development

No branches or pull requests

2 participants