NeedlePlot Examples and Reference


Default NeedlePlot

An example of a default NeedlePlot component without any extra properties.

import json
import six.moves.urllib.request as urlreq
from six import PY3

import dash
import dash_bio as dashbio
import dash_html_components as html
import dash_core_components as dcc


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

data = urlreq.urlopen(
    'https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/' +
    'needle_PIK3CA.json'
).read()

if PY3:
    data = data.decode('utf-8')

mdata = json.loads(data)

app.layout = html.Div([
    "Show or hide range slider",
    dcc.Dropdown(
        id='needleplot-rangeslider',
        options=[
            {'label': 'Show', 'value': 1},
            {'label': 'Hide', 'value': 0}
        ],
        clearable=False,
        multi=False,
        value=1
    ),
    dashbio.NeedlePlot(
        id='my-dashbio-needleplot',
        mutationData=mdata
    )
])


@app.callback(
    dash.dependencies.Output('my-dashbio-needleplot', 'rangeSlider'),
    [dash.dependencies.Input('needleplot-rangeslider', 'value')]
)
def update_needleplot(show_rangeslider):
    return True if show_rangeslider else False


if __name__ == '__main__':
    app.run_server(debug=True)
Show or hide range slider

Needle Style

Change the appearance of the needles.

import json
import six.moves.urllib.request as urlreq
from six import PY3

import dash_bio as dashbio


data = urlreq.urlopen("https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/needle_PIK3CA.json").read()

if PY3:
    data = data.decode('utf-8')

mdata = json.loads(data)

dashbio.NeedlePlot(
    mutationData=mdata,
    needleStyle={
        'stemColor': '#FF8888',
        'stemThickness': 2,
        'stemConstHeight': True,
        'headSize': 10,
        'headColor': ['#FFDD00', '#000000']
    }
)  

Domain Style

Change the appearance of the domains.

import json
import six.moves.urllib.request as urlreq
from six import PY3

import dash_bio as dashbio


data = urlreq.urlopen("https://raw.githubusercontent.com/plotly/dash-bio-docs-files/master/needle_PIK3CA.json").read()

if PY3:
    data = data.decode("utf-8")

mdata = json.loads(data)

dashbio.NeedlePlot(
    mutationData=mdata,
    domainStyle={
        'displayMinorDomains': True,
        'domainColor': ['#FFDD00', '#00FFDD', '#0F0F0F', '#D3D3D3']
    }
)  

Access this documentation in your Python terminal with:
```python

help(dash_bio.NeedlePlot)
```

id (string; optional): The ID of this component, used to identify dash components in callbacks. The ID needs to be unique across all of the components in an app.

domainStyle (dict; default { displayMinorDomains: false, domainColor: [ '#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f', '#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', ], }): Options for the protein domain coloring. domainStyle has the following type: dict containing keys ‘domainColor’, ‘displayMinorDomains’. Those keys have the following types:

  • domainColor (list; optional)
  • displayMinorDomains (boolean; optional)

mutationData (dict; default { x: [], y: [], domains: [], mutationGroups: [], }): The data that are displayed on the plot. mutationData has the following type: dict containing keys ‘x’, ‘y’, ‘mutationGroups’, ‘domains’. Those keys have the following types:

  • x (string | list; optional)
  • y (string | list; optional)
  • mutationGroups (list of strings; optional)
  • domains (list; optional)

needleStyle (dict; default { stemColor: '#444', stemThickness: 0.5, stemConstHeight: false, headSize: 5, headColor: [ '#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999', '#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999', '#e41a1c', ], headSymbol: 'circle', }): Options for the needle marking single site mutations. needleStyle has the following type: dict containing keys ‘stemColor’, ‘stemThickness’, ‘stemConstHeight’, ‘headSize’, ‘headColor’, ‘headSymbol’. Those keys have the following types:

  • stemColor (string; optional)
  • stemThickness (number; optional)
  • stemConstHeight (boolean; optional)
  • headSize (number; optional)
  • headColor (list | string; optional)
  • headSymbol (list | string; optional)

rangeSlider (boolean; default False): If true, enables a rangeslider for the x-axis.

xlabel (string; optional): Title of the x-axis.

ylabel (string; optional): Title of the y-axis.