如何使用范围滑块更改 genomewideline_value 火山图
How to change genomewideline_value of volcano plot with Range Slider
我正在尝试制作火山图,我想根据范围滑块值更改 genomewideline_value
,但它不起作用。下面是我的示例代码:
import pandas as pd
import dash
from dash.dependencies import Input, Output
import dash_bio as dashbio
from dash import html, dcc
app = dash.Dash(__name__)
df = pd.read_csv('https://git.io/volcano_data1.csv')
app.layout = html.Div([
'Effect sizes',
dcc.RangeSlider(
id='default-volcanoplot-input',
min=-3,
max=3,
step=0.05,
marks={i: {'label': str(i)} for i in range(-3, 3)},
value=[-0.5, 1]
),
dcc.RangeSlider(
id='default-volcanoplot-input-2',
min=-3,
max=3,
step=0.05,
marks={j: {'label': str(j)} for j in range(-3, 3)},
value=[0.5]
),
html.Br(),
html.Div(
dcc.Graph(
id='dashbio-default-volcanoplot',
figure={}
)
)
])
@app.callback(
Output('dashbio-default-volcanoplot', 'figure'),
[Input('default-volcanoplot-input', 'value'),
Input('default-volcanoplot-input-2', 'value')]
)
def update_volcanoplot(effects,effects_2):
return dashbio.VolcanoPlot(
dataframe=df,
effect_size='EFFECTSIZE',
logp=True,
p='P',
snp=None,
gene='GENE',
genomewideline_value=effects_2,
genomewideline_width = 1,
effect_size_line=effects,
effect_size_line_width = 1,
xlabel='log2 Fold Change',
ylabel='-(p-adjusted)')
if __name__ == '__main__':
app.run_server(debug=False)
当运行这段代码时,它有错误说:ValueError: ('Lengths must match to compare', (9934,), (1,))
如果我将 genomewideline_value=effects_2
更改为 genomewideline_value=0.5
,效果很好,但我无法通过滑块更改它。
遇到这种情况我该怎么办。谢谢。
我不使用 occasional 或 Dash,但我想当我 运行 你的代码时我注意到 genomewideline_value 只接受一个值而不是 运行 ge值。如果我将它从 运行ge 滑块更改为下拉列表,则更改符合预期。我已经在带有 jupyter_dash 模块的 Colab 环境中对此进行了测试,因此请根据您的环境对其进行修改。
import pandas as pd
import dash
from dash.dependencies import Input, Output
import dash_bio as dashbio
from dash import html, dcc
#app = dash.Dash(__name__)
app = JupyterDash(__name__)
df = pd.read_csv('https://git.io/volcano_data1.csv')
#print(df)
app.layout = html.Div([
'Effect sizes',
dcc.RangeSlider(
id='default-volcanoplot-input',
min=-3,
max=3,
step=0.05,
marks={i: {'label': str(i)} for i in range(-3, 3)},
value=[-0.5, 1]
),
dcc.Dropdown(id='volcanpplot_dp',
options=[0,1,2,3,4,5,6,7,8],
value=4
),
html.Br(),
html.Div(
dcc.Graph(
id='dashbio-default-volcanoplot',
figure=dashbio.VolcanoPlot(
dataframe=df
)
)
)
])
@app.callback(
Output('dashbio-default-volcanoplot', 'figure'),
[
Input('default-volcanoplot-input', 'value'),
Input('volcanpplot_dp', 'value')
]
)
def update_volcanoplot(effects, effects2):
return dashbio.VolcanoPlot(
dataframe=df,
point_size=8,
genomewideline_value=effects2,
genomewideline_width=2,
effect_size_line=effects,
effect_size_line_width=2,
)
if __name__ == '__main__':
app.run_server(debug=True, mode='inline')
我正在尝试制作火山图,我想根据范围滑块值更改 genomewideline_value
,但它不起作用。下面是我的示例代码:
import pandas as pd
import dash
from dash.dependencies import Input, Output
import dash_bio as dashbio
from dash import html, dcc
app = dash.Dash(__name__)
df = pd.read_csv('https://git.io/volcano_data1.csv')
app.layout = html.Div([
'Effect sizes',
dcc.RangeSlider(
id='default-volcanoplot-input',
min=-3,
max=3,
step=0.05,
marks={i: {'label': str(i)} for i in range(-3, 3)},
value=[-0.5, 1]
),
dcc.RangeSlider(
id='default-volcanoplot-input-2',
min=-3,
max=3,
step=0.05,
marks={j: {'label': str(j)} for j in range(-3, 3)},
value=[0.5]
),
html.Br(),
html.Div(
dcc.Graph(
id='dashbio-default-volcanoplot',
figure={}
)
)
])
@app.callback(
Output('dashbio-default-volcanoplot', 'figure'),
[Input('default-volcanoplot-input', 'value'),
Input('default-volcanoplot-input-2', 'value')]
)
def update_volcanoplot(effects,effects_2):
return dashbio.VolcanoPlot(
dataframe=df,
effect_size='EFFECTSIZE',
logp=True,
p='P',
snp=None,
gene='GENE',
genomewideline_value=effects_2,
genomewideline_width = 1,
effect_size_line=effects,
effect_size_line_width = 1,
xlabel='log2 Fold Change',
ylabel='-(p-adjusted)')
if __name__ == '__main__':
app.run_server(debug=False)
当运行这段代码时,它有错误说:ValueError: ('Lengths must match to compare', (9934,), (1,))
如果我将 genomewideline_value=effects_2
更改为 genomewideline_value=0.5
,效果很好,但我无法通过滑块更改它。
遇到这种情况我该怎么办。谢谢。
我不使用 occasional 或 Dash,但我想当我 运行 你的代码时我注意到 genomewideline_value 只接受一个值而不是 运行 ge值。如果我将它从 运行ge 滑块更改为下拉列表,则更改符合预期。我已经在带有 jupyter_dash 模块的 Colab 环境中对此进行了测试,因此请根据您的环境对其进行修改。
import pandas as pd
import dash
from dash.dependencies import Input, Output
import dash_bio as dashbio
from dash import html, dcc
#app = dash.Dash(__name__)
app = JupyterDash(__name__)
df = pd.read_csv('https://git.io/volcano_data1.csv')
#print(df)
app.layout = html.Div([
'Effect sizes',
dcc.RangeSlider(
id='default-volcanoplot-input',
min=-3,
max=3,
step=0.05,
marks={i: {'label': str(i)} for i in range(-3, 3)},
value=[-0.5, 1]
),
dcc.Dropdown(id='volcanpplot_dp',
options=[0,1,2,3,4,5,6,7,8],
value=4
),
html.Br(),
html.Div(
dcc.Graph(
id='dashbio-default-volcanoplot',
figure=dashbio.VolcanoPlot(
dataframe=df
)
)
)
])
@app.callback(
Output('dashbio-default-volcanoplot', 'figure'),
[
Input('default-volcanoplot-input', 'value'),
Input('volcanpplot_dp', 'value')
]
)
def update_volcanoplot(effects, effects2):
return dashbio.VolcanoPlot(
dataframe=df,
point_size=8,
genomewideline_value=effects2,
genomewideline_width=2,
effect_size_line=effects,
effect_size_line_width=2,
)
if __name__ == '__main__':
app.run_server(debug=True, mode='inline')