'How to change genomewideline_value of volcano plot with Range Slider
I'm trying to make a volcano plot and I want to change genomewideline_value based on Range Slider value but it not worked. Below is my sample code:
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)
When running this code, it has error that said: ValueError: ('Lengths must match to compare', (9934,), (1,))
If I change genomewideline_value=effects_2 to genomewideline_value=0.5it worked well but I cannot change it by slider.
What should I do in this case. Thank you.
Solution 1:[1]
I don't use occasional or Dash, but I think what I noticed when I ran your code is that genomewideline_value only accepts a single value instead of taking a range value. if I change it from a range slider to a drop down, the change is as intended. I have tested this in the Colab environment with the jupyter_dash module in place, so please modify it for your environment.
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')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | r-beginners |

