python - 根据 Python 中的先前选择更改下拉选项 ipywidgets
问题描述
我在 Jupyter Notebook 中的代码如下所示:
# Ask user for the Site they would like to view data for
Site = input("Enter the Site number that you would like to see data for: ")
# Choose the dataset based on the user input
if Site == '1':
df = site1_df
else:
df = site2_df
在下面的单元格中,我有一个交互式绘图单元格,使用ipywidgets
如下:
@interact
def line_plot(Variable=list(df.select_dtypes('number').columns),
time=widgets.ToggleButtons(options=['Raw', 'Minute', 'Hour', 'Day', 'Month'],
description='Time'),
color_button=widgets.ToggleButtons(options=['polar', 'solar', 'henanigans'],
description='Plot Theme'),
color_scale=widgets.ToggleButtons(options=['spectral', 'pastel1', 'polar', 'dark2'],
description='Colour Scale')):
# The following resamples the data based on the user selection
if time == 'Raw':
new_df = df.resample('30S').mean()
elif time == 'Minute':
new_df = df.resample('T').mean()
elif time == 'Hour':
new_df = df.resample('H').mean()
elif time == 'Day':
new_df = df.resample('D').mean()
else:
new_df = df.resample('M').mean()
# The newly resampled data is then plotted based on the users choice
new_df.iplot(kind='line', y=Variable, xTitle='Time', yTitle='Test',
mode='lines', theme=color_button, colorscale=color_scale)
我还必须做其他优化元素,但我希望将Site
选择作为下拉菜单,就像所附屏幕截图中的其他元素一样。但是我似乎无法集成它,从而为 , 选择的选项Site
更改了Variables
显示的选项。我已经看过其他一些帖子,但似乎无法根据我的情况整合它。欢迎任何帮助!
解决方案
推荐阅读
- c# - Telerik 下拉控件不允许我从下拉列表中选择项目
- azure - 使用 Azure Powershell cmdlet New-AzVM 创建 Windows 10 VM
- laravel - 为什么 Laravel 每次请求都会生成一个新会话?
- shell - 从日志文件中过滤掉 uniq 行
- excel - 为 If 语句引用“onclick”事件 - IE 自动化
- pdf - pdf文本不对齐
- firebase - 使用 orderByKey 在 Firebase 数据库中搜索值不起作用 DailogFlow
- python - asyncio 添加附加功能
- java - 在泽西资源类测试中模拟 HttpServletRequest 类
- python - 使用 Python 获取电子邮件正文中的数据