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

IntRangeSlider not providing Integers as values #859

Closed
Acosta-Goncalves opened this issue Dec 9, 2019 · 0 comments · Fixed by #876
Closed

IntRangeSlider not providing Integers as values #859

Acosta-Goncalves opened this issue Dec 9, 2019 · 0 comments · Fixed by #876
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@Acosta-Goncalves
Copy link

Acosta-Goncalves commented Dec 9, 2019

Panel Version 0.6.4, Jupyter Notebook with Python 3.6 running on MacOS Mojave

Using a pn.widgets.IntRangeSlider to select a month range, I wanted to display the name of the selected months on the title of the plot. I used python's calendar library (import calendar) to get the name via calendar.month_name[selected_month].

When the plot loads the first time, the calendar.month_name works correctly and displays the default widget values (in this case August & October). But when you move the slider to select other months, then calendar.month_name[...] crashes because it is no longer receiving an integer. I have to wrap the value from the widget in np.int() to force an integer, so instead of calendar.month_name[sel_months[0]], I need to write calendar.month_name[np.int(sel_months[0])]

In my view, the np.int function should not be necessary since you'd expect an IntRangeSlider to provide Integers as values.

Either way, the behaviour should be consistent. If you need to wrap the widget's values in np.int(), then it should also happen the first time the plot is loading with the default values. Because otherwise —as was my case— you assume that calendar.month_name[sel_months[0]] is working fine (since it's displaying names), and it takes you ages to discover that the problem is there.

To reproduce the issue:

# Widget to select the MONTH RANGE
month_range_slider = pn.widgets.IntRangeSlider(name='Month Range', start=1, end=12,
                                               value=(8, 10), step=1, width=150)

@pn.depends(sel_months=month_range_slider)  
def plot_monthly_currents(sel_months):
    plt.figure()
    plt.title(f"Selected months:{calendar.month_name[sel_months[0]]} & {calendar.month_name[sel_months[1]]}", 
              fontsize=20, pad=20)
    curr_fig=plt.gcf()  
    plt.close(curr_fig) 
    return curr_fig

pn.Column(month_range_slider,
          plot_monthly_currents)

image

Thanks for this great libray! ^_^

@Acosta-Goncalves Acosta-Goncalves added the TRIAGE Default label for untriaged issues label Dec 9, 2019
@philippjfr philippjfr added type: bug Something isn't correct or isn't working and removed TRIAGE Default label for untriaged issues labels Dec 9, 2019
@philippjfr philippjfr added this to the v0.7.1 milestone Dec 9, 2019
@philippjfr philippjfr modified the milestones: v0.7.1, v0.8.0 Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants