Skip to content

Made hvplot API dynamic by accepting parameter/widget instances#323

Merged
jsignell merged 3 commits intomasterfrom
panel_dynamic
Oct 7, 2019
Merged

Made hvplot API dynamic by accepting parameter/widget instances#323
jsignell merged 3 commits intomasterfrom
panel_dynamic

Conversation

@jsignell
Copy link
Member

@jsignell jsignell commented Oct 2, 2019

NEW: Replacing #279 and updating to accept widgets as well as parameters.

This PR makes it possible to build GUIs by passing parameters instances directly into the hvPlot methods. Combined with Panel this makes it very easy to build complex GUIs.

import panel as pn
import hvplot.pandas

from bokeh.sampledata.iris import flowers

cols = list(flowers.columns[:-1])
x = pn.widgets.Select(name='x', value='sepal_length', options=cols)
y = pn.widgets.Select(name='y', value='sepal_width', options=cols)
kind = pn.widgets.Select(name='kind', value='scatter', options=['bivariate', 'scatter'])
by_species = pn.widgets.Checkbox(name='By species')
color = pn.widgets.ColorPicker(value='#ff0000')

@pn.depends(by_species, color)
def by_species_fn(by_species, color):
    return 'species' if by_species else color

plot = flowers.hvplot(x=x, y=y, kind=kind, c=by_species_fn)

pn.Row(pn.WidgetBox(x, y, kind, color, by_species), plot)

iris_explorer

This examples demonstrate how both parameters and functions that depend on some parameter(s) can be used to dynamically update a plot. In this case the by_species_fn returns either the 'species' column or the ColorPicker depending on whether the checkbox is ticked, making it simple to specify even complex behaviors.

Currently this re-renders the plot every time a parameter changes. A future exercise can be to optimize this by handling certain parameters internally using DynamicMaps.

  • Clean up code
  • Add docs
  • Add tests

closes #325

@jsignell jsignell changed the title Made hvplot API dynamic by accepting parameter/widget instances [WIP] Made hvplot API dynamic by accepting parameter/widget instances Oct 2, 2019
@jsignell
Copy link
Member Author

jsignell commented Oct 3, 2019

I am exposing this as well:

import panel as pn
import hvplot.pandas

from bokeh.sampledata.iris import flowers

flowers.hvplot.scatter(groupby='species', legend='top_right', 
                       widgets={'species': pn.widgets.DiscreteSlider})

Screen Shot 2019-10-03 at 1 41 15 PM

@jsignell jsignell changed the title [WIP] Made hvplot API dynamic by accepting parameter/widget instances Made hvplot API dynamic by accepting parameter/widget instances Oct 3, 2019
@jsignell jsignell requested a review from philippjfr October 3, 2019 18:05
@jsignell jsignell merged commit 824d596 into master Oct 7, 2019
@jsignell jsignell deleted the panel_dynamic branch October 7, 2019 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Users should be able to specify which widgets they want for groupby

1 participant