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

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

Merged
merged 3 commits into from
Oct 7, 2019

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 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