python dash callback_Python Dash:将pandas数据帧加载到数据表中

我一直在尝试用

Dash

大多数示例说明如何手动从示例中已硬编码的数据帧中选取某些列/行,如

here

pd.Dataframe()

变成一个

dash_table.DataTable()

.

我该怎么做?使用这些引用,我尝试了以下代码将数据帧的dict发送到

,但没有显示任何内容。

## Imports

import dash

import dash_core_components as dcc

import dash_html_components as html

import dash_table

from dash.dependencies import Input, Output, State

import datetime as dt

import pandas as pd

import numpy as np

## Custom functions that creates the pandas dataframe

from twitter_functions import old_tweets

app = dash.Dash(dev_tools_hot_reload=True)

app.scripts.config.serve_locally = True

app.config['suppress_callback_exceptions'] = True

app.layout = html.Div(children=[

html.H3('Twitter App'),

dcc.Input('ScreenName_Input', type='text'),

html.Button(id='screenNames_submit_button', children='Submit'),

dash_table.DataTable(id='tweet_table')

])

@app.callback(

Output(component_id='tweet_table', component_property='data'),

[Input(component_id='screenNames_submit_button', component_property='n_clicks_timestamp')],

[State(component_id='ScreenName_Input', component_property='value')]

)

def display_tweets(submit_button, screen_names):

tweets = old_tweets(screen_names)

return tweets.to_dict(orient='records')

if __name__ == '__main__':

app.run_server(debug=True)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值