将下拉列表更新选项代码放入Jupyter Notebook中的函数中时不起作用

问题描述

我编写了一个代码,以在用户选择特定的Year值后立即更新Month的下拉选项。这是代码

YearW = widgets.Dropdown(options=drop_options.keys())
init = YearW.value
MonthW = widgets.Dropdown(options=drop_options[init])
        
display(widgets.interactive(main_function,Year=YearW,Month=MonthW))

我还将这一行放在main_function()的末尾:

MonthW.options = drop_options[Year]

但是,一旦将其放入函数中,该方法将不起作用并且值也不会更新

 def chart_selection(chart_type):
        if(chart_type=='Line graph - Volume of reviews'):
            
            YearW = widgets.Dropdown(options=drop_options.keys())
            init = YearW.value
            MonthW = widgets.Dropdown(options=drop_options[init])
            
            display(widgets.interactive(main_function,Month=MonthW))
            
        elif(chart_type=='Pie chart - Sentiment analysis'):
            #display(widgets.interactive(main_function,Month=MonthW))

我很困惑在哪里使用observe()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)