admin管理员组文章数量:1314015
The following code dynamically reads Python files from the pages module. Each file contains a create_page
function, which returns objects like pn.Column
that can be rendered in Panel.
My design is to dynamically read each Python file, create one button for each file in the sidebar, and, upon clicking a button, replace the content of the main area with the content returned by the corresponding create_page
function.
import panel as pn
import pkgutil
import importlib
pages = dict()
for _, page, _ in pkgutil.iter_modules(["pages"]):
pages[page] = importlib.import_module(f"pages.{page}")
template = pn.template.FastListTemplate(
title="Muti pages demo",
site="Web main"
)
def change_main_content(event):
template.main.clear()
template.main.append(pages[event.obj.name].create_page())
def change_main_content_str(event):
print(event)
template.main.clear()
template.main.append(pages[event].create_page())
for page in pages.keys():
page_button = pn.widgets.Button(name=page)
# Issue: Clicking the button to trigger the change_main_content_str function
# does not update the main area!
page_button.on_click(lambda event: change_main_content_str(event.obj.name))
# However, calling the function directly works as expected!
change_main_content_str("data")
template.sidebar.append(page_button)
template.servable()
Why does this issue occur? How can it be fixed?
本文标签: python module panel can not update main areaStack Overflow
版权声明:本文标题:python module panel can not update main area - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741958746a2407143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论