美文网首页
python dash

python dash

作者: 垃圾桶边的狗 | 来源:发表于2022-06-08 22:17 被阅读0次

    文档

    from dash import Dash, html, Input, Output, callback, dcc
    from dash import dash_table as dt
    import dash_bootstrap_components as dbc
    import pandas as pd
    import colorlover as cl
    
    colorscale = cl.scales['9']['qual']['Paired']
    
    df = pd.read_parquet('./tmpcare.parquet')
    df1 = pd.read_parquet('./tmpret.parquet')
    
    app = Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
    
    app.layout = html.Div([
        html.Div([html.H2("haha", style={"text-align": "center",})]),
    
        html.Div([dt.DataTable(
            id='tbl',
            data=df.to_dict('records'),
            columns=[{"name": i, "id": i} for i in df.columns],
        )]),
        html.H2("自选"),
        dcc.Dropdown(
            id='stock-input',
            options=[{'label': i[0], 'value': i[1]} for i in zip(df.id.unique(), df.id.unique())],
            value=['aa', 'bb'],
            multi=True,
            style={'color': 'red','width':'800px'}
        ),
    
        html.Div(id='graph', style={'color':'blue'}),
    
    ], className="container")
    
    
    @callback(
        Output('graph', 'children'),
        Input("stock-input", "value")
    )
    def update_graph(value):
    
        if not value:
            return
        data = [{
            'x': df1[col].index.map(str),
            'y': df1[col].to_list(),
            'type': 'line',
            'name': col
        } for col in value]
    
        return dcc.Graph(
            figure={
                'data': data,
                'layout': {
                    'title': 'Tendency Chart',
                    # 'width':"400px",
                    'border':'3px'
                }
            }
        )
    
    
    
    if __name__ == '__main__':
        app.run_server(debug=True, host='0.0.0.0', port=9000)
    
    
    img.png

    相关文章

      网友评论

          本文标题:python dash

          本文链接:https://www.haomeiwen.com/subject/bdrpmrtx.html