我正在构建一个仪表板,该仪表板根据输入的日期生成报告。报告中生成了5个csv,并以下拉方式显示并可供下载。问题在于,一旦生成新报告,正在读取csv的数据帧就不会更新。它仍然保存上一次运行的数据。我该如何解决?
from kontekst_report_server_datewise import kontekst
def generate_table(dataframe,max_rows=10):
return html.Table(
# Header
[html.Tr([html.Th(col) for col in dataframe.columns])] +
# Body
[html.Tr([
html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), max_rows))]
)
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
# external_stylesheets = ['https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.DatePickerRange(id='date-picker-range',
start_date=datetime(2019, 4, 3), end_date=datetime(2019, 4, 4)),
dcc.Dropdown(
id='my-dropdown',
options=[
{'label' : 'Returns Summary' , 'value' : 'df1'},
{'label' : 'Return Guide Doc Details' , 'value' : 'df2'},
{'label' : 'Return Guide id Counts' , 'value' : 'df3'},
{'label' : 'Non Return Guide id Counts', 'value' : 'df4'},
{'label' : 'Order Creation Details' , 'value' : 'df5'}
],
# value='df1'
# multi = True
),
html.Div(id='output-container'),
html.A('Download CSV', id = 'my-link'),
html.Div(id='kontekst')
])
@app.callback(
dash.dependencies.Output('output-container', 'children'),
[dash.dependencies.Input('my-dropdown', 'value')])
def update_output(value):
df1 = pd.read_csv('returns_summary.csv')
df2 = pd.read_csv('ReturnGuideDocDetails.csv')
df3 = pd.read_csv('Return_guideid_counts.csv')
df4 = pd.read_csv('NonReturn_guideid_counts.csv')
df5 = pd.read_csv('OrderCreationdetails.csv')
if value == 'df1':
return generate_table(df1)
elif value == 'df2':
return generate_table(df2)
elif value == 'df3' :
return generate_table(df3)
elif value == 'df4' :
return generate_table(df4)
elif value == 'df5' :
return generate_table(df5)
@app.callback(Output('my-link', 'href'), [Input('my-dropdown', 'value')])
def update_link(value):
return '/dash/urlToDownload?value={}'.format(value)
if __name__ == '__main__':
app.run_server(debug=True)```