gpt4 book ai didi

python - 当我用 Bokeh 中另一个选择小部件中的新值更新它时,删除以前的选择小部件

转载 作者:太空宇宙 更新时间:2023-11-03 21:05:35 25 4
gpt4 key购买 nike

我将在选择小部件中选择一个“日期”,然后根据我之前选择的值,将出现另一个选择小部件。如果我再次选择以前的“日期”选择小部件,则会再次出现一个新的选择小部件,但以前的选择小部件仍然会在那里。当我更改日期选择小部件中的值时,必须将其删除。有什么解决办法吗?

我尝试了 curdoc().clear 但它清除了更改中的所有内容。仅需要清除特定的小部件。

from bokeh.models.widgets import Div
import numpy as np
import pandas as pd

from bokeh.models.widgets import Tabs,Panel
welcome_message = 'Operator selected: (none)'
text_banner = Paragraph(text=welcome_message, width=200, height=100)

def callback_print(text_banner=text_banner):
user_input = str(cb_obj.value)
welcome_message = 'Operator selected: ' + user_input
text_banner.text = welcome_message
tabs.reset.emit()
#reaction_time.reset.emit()

def my_text_input_handler(attr, old, new):
print("Previous label: " + old)
print("Updated label: " + new)

root= join(dirname(__file__),str(new))
dirlist = [ item for item in os.listdir(root) if
os.path.isdir(os.path.join(root, item)) ]

available_date = dirlist
available_date += ['None']

def update(attr, old, new1):
root1= join(dirname(__file__),str(new),str(new1))
dirlist1 = [ item for item in os.listdir(root1) if
os.path.isdir(os.path.join(root1, item)) ]

available_level = dirlist1
available_level += ['None']

def update(attr, old, new2):


user_data = pd.read_csv(join(dirname(__file__),str(new),str(new1),str(new2),'test1.txt'), sep=",",na_filter =None)
data = user_data.copy()
#############################################
########PYTHON CODE ##########################
##############################################
##############################################
# Create each of the tabs
### ALL Tabs
# Put all the tabs into one application
tabs = Tabs(tabs = [tab1,tab2,tab3,tab4,tab5,tab6,tab7])
curdoc().clear()
layout = column(title,tabs,sizing_mode='scale_width')
curdoc().add_root(layout)

level_selection = Select(title="Select a Level : " ,value = 'None', options=available_level)
level_selection.on_change('value', update1)
curdoc().add_root(widgetbox(level_selection))


date_selection = Select(title="Select a date : " ,value = 'None', options=available_date)
date_selection.on_change('value', update)
layout1 = widgetbox(date_selection)
curdoc().add_root(layout1)


# Put the tabs in the current document for display

text_input = TextInput( title="Enter operator
Name:",callback=CustomJS.from_py_func(callback_print),css_classes=
['customTextInput'])
text_input.on_change('value', my_text_input_handler)
curdoc().add_root(widgetbox(text_input))

Select Widget Display image

最佳答案

根据您添加的代码和评论讨论,我认为这应该适合您:

from bokeh.models import Div, Paragraph, Select, TextInput, CustomJS, WidgetBox
from bokeh.plotting import curdoc
import numpy as np
import pandas as pd
import os

from bokeh.models.widgets import Tabs, Panel
welcome_message = 'Operator selected: (none)'
text_banner = Paragraph(text = welcome_message, width = 200, height = 100)

current_date = None

def callback_print(text_banner = text_banner):
user_input = str(cb_obj.value)
welcome_message = 'Operator selected: ' + user_input
text_banner.text = welcome_message
tabs.reset.emit()
# reaction_time.reset.emit()

def my_text_input_handler(attr, old, new):
print("Previous label: " + old)
print("Updated label: " + new)

root = os.path.join(dirname(__file__), str(new))
dirlist = [ item for item in os.listdir(root) if
os.path.isdir(os.path.join(root, item)) ]

available_date = dirlist
available_date += ['None']

def update(attr, old, new1):
root1 = os.path.join(dirname(__file__), str(new), str(new1))
dirlist1 = [ item for item in os.listdir(root1) if
os.path.isdir(os.path.join(root1, item)) ]

available_level = dirlist1
available_level += ['None']

global current_date
if current_date is not None:
layout1.children.remove(layout1.children[0])

def update(attr, old, new2):
user_data = pd.read_csv(join(dirname(__file__), str(new), str(new1), str(new2), 'test1.txt'), sep = ",", na_filter = None)
data = user_data.copy()
#############################################
########PYTHON CODE ##########################
##############################################
##############################################
# Create each of the tabs
# ## ALL Tabs
# Put all the tabs into one application
tabs = Tabs(tabs = [tab1, tab2, tab3, tab4, tab5, tab6, tab7])
curdoc().clear()
layout = column(title, tabs, sizing_mode = 'scale_width')
curdoc().add_root(layout)

level_selection = Select(title = "Select a Level : " , value = 'None', options = available_level)
level_selection.on_change('value', update1)
curdoc().add_root(WidgetBox(level_selection))
current_date = new1

date_selection = Select(title = "Select a date : " , value = 'None', options = available_date)
date_selection.on_change('value', update)
layout1 = WidgetBox(date_selection)
curdoc().add_root(layout1)

# Put the tabs in the current document for display

text_input = TextInput(title = "Enter operator Name:", callback = CustomJS.from_py_func(callback_print), css_classes = ['customTextInput'])
text_input.on_change('value', my_text_input_handler)
curdoc().add_root(WidgetBox(text_input))

关于python - 当我用 Bokeh 中另一个选择小部件中的新值更新它时,删除以前的选择小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55430129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com