# dash_bioOncoPrint Examples and Reference

see OncoPrint in action.

## OncoPrint

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

autosize: True

    library(jsonlite)
    library(dash)
    library(dashHtmlComponents)
    library(dashCoreComponents)
    library(dashBio)

    app <- Dash$new()

    data = read_json("https://git.io/oncoprint_dataset3.json")

    app$layout(htmlDiv(list(
        dashbioOncoPrint(
            data = data,
            id = "dashbio-default-oncoprint"
        ),
        htmlDiv(id = 'default-oncoprint-output')
    )))

    app$callback(
        output(id = "default-oncoprint-output", property = "children"),
        params = list(
            input(id = 'dashbio-default-oncoprint', property = "eventDatum")
        ),

        update_output <- function(event_data) {
            if (is.null(event_data)) {
                return("There is no event data. Hover over or click on a part of the graph to generate event data.")
            }

            else {
                return(htmlDiv(
                    sprintf("Event Data: %s", event_data)
                ))
            }

        }
    )

    app$run_server()

## Customization

### Colors

Change the color of specific mutations, as well as the background color.

    library(dashBio)

    data = read_json("https://git.io/oncoprint_dataset3.json")

    dashbioOncoPrint(
        data = data,
        colorscale = list(
            "MISSENSE" = "#e763fa",
            "INFRAME"  = "#E763FA"
        ),
        backgroundcolor = "#F3F6FA"
    )

### Size And Spacing

Change the height and width of the component, and adjust the spacing between adjacent tracks.

    library(dashBio)

    data = read_json("https://git.io/oncoprint_dataset3.json")

    dashbioOncoPrint(
        data = data,
        height = 800,
        width = 500,
        padding = 0.25
    )

### Legend And Overview

Show or hide the legend and/or overview heatmap.

    library(dashBio)

    data = read_json("https://git.io/oncoprint_dataset3.json")

    dashbioOncoPrint(
        data=data,
        showlegend = FALSE,
        showoverview = FALSE
    )

## OncoPrint Properties

> Our recommended IDE for writing Dash apps is Dash Enterprise's Data Science Workspaces, which has typeahead support for Dash Component Properties. Find out if your company is using Dash Enterprise.

`id` (character; optional): The ID of this component, used to identify dash components in callbacks. The ID needs to be unique to the component.

`eventDatum` (named list; optional): A Dash prop that returns data on clicking, hovering or resizing the viewer.

`data` (unnamed list; optional): Input data, in CBioPortal format where each list entry is a dict consisting of 'sample', 'gene', 'alteration', and 'type'.

`padding` (numeric; default `0.05`): Adjusts the padding (as a proportion of whitespace) between two tracks. Value is a ratio between 0 and 1. Defaults to 0.05 (i.e., 5 percent). If set to 0, plot will look like a heatmap.

`colorscale` (logical | named list; optional): If not NULL, will override the default OncoPrint colorscale. Default OncoPrint colorscale same as CBioPortal implementation. Make your own colrscale as a {'mutation': COLOR} dict. Supported mutation keys are ['MISSENSE, 'INFRAME', 'FUSION', 'AMP', 'GAIN', 'HETLOSS', 'HMODEL', 'UP', 'DOWN'] Note that this is NOT a standard plotly colorscale.

`backgroundcolor` (character; default `'rgb(190, 190, 190)'`): Default color for the tracks, in common name, hex, rgb or rgba format. If left blank, will default to a light grey rgb(190, 190, 190).

`range` (unnamed list; default `[NULL, NULL]`): Reset windowing to user preset on initial range or data change.

`showlegend` (logical; default `TRUE`): Toogles whether or not to show a legend on the right side of the plot, with mutation information.

`showoverview` (logical; default `TRUE`): Toogles whether or not to show a heatmap overview of the tracks.

`width` (numeric | character; optional): Width of the OncoPrint. Will disable auto-resizing of plots if set.

`height` (numeric | character; default `500`): Height of the OncoPrint. Will disable auto-resizing of plots if set.

`loading_state` (named list; optional): Object that holds the loading state object coming from dash-renderer.

`loading_state` is a named list with keys:

- `component_name` (character; optional): Holds the name of the component that is loading.

- `is_loading` (logical; optional): Determines if the component is loading or not.

- `prop_name` (character; optional): Holds which property is loading.

## Example Data

- https://github.com/plotly/datasets/blob/master/Dash_Bio/Chromosomal/oncoprint_dataset3.json