【问题标题】:panel/holoviz dynamically update a section of the templatepanel/holoviz 动态更新模板的一部分
【发布时间】:2022-11-08 18:50:42
【问题描述】:

这是我的第一个面板项目。 我无法在模板的主要部分显示新元素。 En effet j'essai d'afficher un graph lorsque je clique sur un button。

我的代码python

import numpy as np
import pandas as pd
from matplotlib.figure import Figure
import hvplot.pandas
import panel as pn


text_input = pn.widgets.TextInput( placeholder='Your question')
button = pn.widgets.Button(value=True,name='Rechercher', button_type='primary')

def get_dataframe(question):
    row_headers = ['vehicle model','driver\'s name','driver\'s firstname','incident 
           place','lieu latitude','lieu longitude','incident date', 'Number of accident']

    data = (('CX 9','Kouakou','Franck','Yamoussoukro',6.816667080,-5.283332825,'2020-10- 
   19 00:00:00', 1), ('CX 9','Kone','Lamine','Abobo',5.432887077,-4.038891792,'2020-10-16 
   08:30:51', 1), ('Ranger 4X4 
   DC','Tano','Hermine','Cocody',5.359376907,-3.995745897,'2021-02-09 08:00:38', 1), 
   ('Pathfinder','Yao','Nadia','Cocody',5.354498386,-3.992352009,'2021-02-15 08:00:23', 1), 
   ('Yaris','Doumbia' ,'Cheick Slymane','Cocody',5.370238781,-3.981418133,'2021-07-10 
   10:00:22', 1), ('Yaris', 'Doumbia','Cheick 
   Slymane','Yopougon',5.349046230,-4.073932171,'2020-03-06 20:00:49', 1), ('Yaris', 
   'Doumbia','Cheick Slymane','Adzope',6.107145786,-3.855350971,'2020-12-20 14:20:47', 1))

    df = pd.DataFrame(data, columns=row_headers)
    return row_headers,data,df



def line_widget(text_input):

    row_headers, data, df = get_dataframe(text_input.value)
    idf = df.interactive()
    tab = []

    accident_pipeline = (idf)
    accident_plot = accident_pipeline.hvplot(x=row_headers[0],y='Number of accident',line_width=2, title='Accident par model')

    return pn.Row(accident_plot)
app = pn.template.FastListTemplate(title='Dashboard',main=[pn.Row(pn.Column(text_input),button)])

@pn.depends(button_inf=button, question=text_input, watch=True)
def _item_selector(button_inf,question):
    if button_inf:
        app.main.append(pn.Row(line_widget(question)))

app.servable()

点击按钮后我得到了什么

fig1

点击按钮后我想要什么

fig2

【问题讨论】:

    标签: dynamic panel holoviz holoviz-panel


    【解决方案1】:

    干得好 我从 holoviz 论坛中发现了类似的“多页应用程序文档”: https://discourse.holoviz.org/t/multi-page-app-documentation/3108/3

    【讨论】:

      猜你喜欢
      • 2020-10-10
      • 2016-09-04
      • 1970-01-01
      • 2020-05-26
      • 2020-07-14
      • 1970-01-01
      • 2014-12-19
      • 1970-01-01
      • 2019-11-16
      相关资源
      最近更新 更多