非常感谢您的帮助!我正在尝试在破折号上建立一个网站。 pg1.py的第一页有一个dcc.Input用于输入数字。我想在新文件new.py中看到回调返回(risk_free_rate)作为计算参数,然后将计算结果输出到新页面pg2.py。我尝试了dcc.Store,但找不到正确的方法。如何将risk_free_rate传输到新文件?当我尝试使用risk_free_rate进行操作(例如打印出来)时,PyCharm会显示一个解决方案–“未解决的参考'risk_free_rate'”。附带的代码。
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from app import app
layout = html.Div([
html.Div([
html.Div([
dcc.Input(id='input_yield', type='number', min=0, step=0.01),
html.Button('Подтвердить', id='submit-button1', n_clicks=None, style={'backgroundColor': '#374d6e',
'color': '#ffffff'})
], style={'backgroundColor': '#25344a', 'display': 'table-cell', 'width': '300px', 'color': '#ffffff',
'padding-left': '25px'}),
html.Div([
html.P(id='srt_data1', style={'display': 'none'})
], style={'backgroundColor': '#374d6e', 'color': '#ffffff', 'display': 'table-cell', 'padding-left': '25px'})
], style={'display': 'table', 'width': '100%'}),
], style={'display': 'table', 'width': '100%'})
@app.callback(
[Output(component_id='srt_data1', component_property='style'),
Output(component_id='srt_data1', component_property='children')],
[Input(component_id='submit-button1', component_property='n_clicks')],
[State('input_yield', 'value')],
prevent_initial_call=True
)
def rfr_choice(n_clicks, input2):
if n_clicks is not None and input2:
risk_free_rate = int(input2)
return [{'display': 'block'},
'{}%'.format(risk_free_rate)]
else:
return [{'display': 'block'}, '404']
print(risk_free_rate)