“我的Dash应用程序”当前除索引页面外还有两个页面,它由以下文件组成。
if len(K) == 0: #CM is the correlation matrix, we have no variables conditioning (K has 0 length)
r = CM[i, j] #r is the partial correlation of i and j
elif len(K) == 1: #we have one variable conditioning, not very different from the previous version except for the fact that i have not to compute the correlations matrix since i start from it, and pandas provide such a feature on a DataFrame
r = (CM[i, j] - CM[i, K] * CM[j, K]) / math.sqrt((1 - math.pow(CM[j, K], 2)) * (1 - math.pow(CM[i, K], 2))) #r is the partial correlation of i and j given K
else: #more than one conditioning variable
CM_SUBSET = CM[np.ix_([i]+[j]+K, [i]+[j]+K)] #subset of the correlation matrix i'm looking for
PM_SUBSET = np.linalg.pinv(CM_SUBSET) #constructing the precision matrix of the given subset
r = -1 * PM_SUBSET[0, 1] / math.sqrt(abs(PM_SUBSET[0, 0] * PM_SUBSET[1, 1]))
r = min(0.999999, max(-0.999999,r))
res = math.sqrt(n - len(K) - 3) * 0.5 * math.log1p((2*r)/(1-r)) #estimating partial correlation with fisher's transofrmation
return 2 * (1 - norm.cdf(abs(res))) #obtaining p-value
我在应用程序的第1页上有一个滑块,即在app1.py中。滑块值是在应用程序第1页上进行绘图的回调的输入。
如果我想对应用程序第2页中的另一个回调使用相同的滑块值来绘制其他内容。如何将滑块值传递到app2.py?
答案 0 :(得分:0)
您可以将其值存储在dcc.Store(https://dash.plot.ly/dash-core-components/store )组件(在app1中):
@app.callback(
Output('dcc_store_compoenent_id', 'data')
[Inputs('your_slider_id', 'value')]
def store_slider_value_in_dcc_store(slider_value):
return {'slider_app1_value': slider_value}
然后,您可以根据需要触发回调(在app2中),并使用dcc.State组件上的State访问数据:
@app.callback(
Output('the_output', 'you_want')
[Inputs('whatever', 'you_want')]
[State('dcc_store_compoenent_id', 'data'])
def func(input_value, data):
slider_value = data['slider_app1_value']
...