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

Make FastGridTemplate reference example more immediately useful #2577

Closed
MarcSkovMadsen opened this issue Jul 27, 2021 · 0 comments
Closed
Labels
type: enhancement Minor feature or improvement to an existing feature
Milestone

Comments

@MarcSkovMadsen
Copy link
Collaborator

MarcSkovMadsen commented Jul 27, 2021

I'm trying to make a video tutorial from the FastGridTemplate Reference Guide. I see a few things that could be improved so that it would be easier for the user to actually get something working in practice.

Solution

  • Use pn.bind api instead of pn.depends. The bind api is more intuitive to data scientists. And it provides a better separation between the normal data science code and the panel specific code.
  • Use the accent_color (pink/ red) instead of blue
  • wrap the DynamicMap into a Column with sizing_mode="stretch_width" in order for the "maximize" functionality associated with a grid cell to work.

Something like the below would do the job

import holoviews as hv
import numpy as np

import panel as pn

pn.extension(sizing_mode="stretch_width")

ACCENT_COLOR = "#DF3874"

# Plots

XS = np.linspace(0, np.pi)

def sine(freq, phase):
    return hv.Curve((XS, np.sin(XS * freq + phase))).opts(
        responsive=True, min_height=400, title="Sine", color=ACCENT_COLOR
    )


def cosine(freq, phase):
    return hv.Curve((XS, np.cos(XS * freq + phase))).opts(
        responsive=True, min_height=400, title="Cosine", color=ACCENT_COLOR
    )


# Widgets

freq = pn.widgets.FloatSlider(name="Frequency", start=0, end=10, value=2)
phase = pn.widgets.FloatSlider(name="Phase", start=0, end=np.pi)

# Interactivity

sine = pn.bind(sine, freq=freq, phase=phase)
cosine = pn.bind(cosine, freq=freq, phase=phase)

# Layout

template = pn.template.FastGridTemplate(title="FastGridTemplate", save_layout=True)

template.sidebar.append(pn.pane.Markdown("## Settings"))
template.sidebar.append(freq)
template.sidebar.append(phase)

template.main[:3, :6] = pn.pane.HoloViews(hv.DynamicMap(sine), sizing_mode="stretch_both")
template.main[:3, 6:] = pn.pane.HoloViews(hv.DynamicMap(cosine), sizing_mode="stretch_both")
template.servable()
@MarcSkovMadsen MarcSkovMadsen added the TRIAGE Default label for untriaged issues label Jul 27, 2021
@MarcSkovMadsen MarcSkovMadsen changed the title Improve FastGridTemplate reference example Make FastGridTemplate reference example more immediately useful Jul 27, 2021
@MarcSkovMadsen MarcSkovMadsen added type: enhancement Minor feature or improvement to an existing feature and removed TRIAGE Default label for untriaged issues labels Jul 27, 2021
@MarcSkovMadsen MarcSkovMadsen added this to the v0.12.1 milestone Jul 27, 2021
philippjfr pushed a commit that referenced this issue Aug 2, 2021
* use bind api and enable full screen (#2577)

* remove \r

* reset

* remove hash

Co-authored-by: Marc Skov Madsen <masma@orsted.dk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants