<!--
%\VignetteEngine{knitr::knitr}
%\VignetteIndexEntry{Using interactiveDisplay for Bioconductor object visualization and modification}
-->

```{r setup, echo=FALSE}
suppressWarnings(suppressPackageStartupMessages(library(knitr)))
options(width=80)
```

```{r wrap-hook, echo=FALSE}
hook_output = knit_hooks$get('output')
knit_hooks$set(output = function(x, options) {
  # this hook is used only when the linewidth option is not NULL
  if (!is.null(n <- options$linewidth)) {
    x = knitr:::split_lines(x)
    # any lines wider than n should be wrapped
    if (any(nchar(x) > n)) x = strwrap(x, width = n)
    x = paste(x, collapse = '\n')
  }
  hook_output(x, options)
})
```

```{r interactiveDisplay-load, echo=FALSE}
suppressWarnings(suppressPackageStartupMessages(library(interactiveDisplay)))
```

# interactiveDisplay

[interactiveDisplay](http://bioconductor.org/packages/2.13/bioc/html/interactiveDisplay.html)

`interactiveDisplay` uses the function `display()` to host a browser based 
application on the fly using the Shiny package.  Currently 4 Bioconductor 
objects: Granges, GrangesList, ExpressionSet and SummarizedExperiment are 
supported with tailored methods.  In some cases, grid based plots are converted 
to SVG with the gridSVG package and additional JavaScript is appended for simple
mousewheel zoom and panning.  Shiny UI elements are available based on the 
object passed to `display()`.  These allow the user to modify how the plot is 
displayed, and for some objects, modify or subset the data and send it back to 
the console.

## Methods

draw an SummarizedExperiment object

```{r SummarizedExperiment_demo, eval=FALSE}
data(se)
display(se)
```


draw a GRanges object

```{r GRanges_demo, eval=FALSE}
data(mmgr)
display(mmgr)
```


draw a GRangesList object

```{r GRangesList_demo, eval=FALSE}
data(mmgrl)
display(mmgrl)
```


draw an ExpressionSet object

```{r ExpressionSet_demo, eval=FALSE}
data(expr)
display(expr)
```

## subsetting

Many of the display method will have a button that allows you return
subset values back to the R session.  To use these, couple the intial
call with an assignment operator like this:

```{r dataframe_demo, eval=FALSE}
mtcars2 <- display(mtcars)
```

Once you leave the diplay web gui, the results of the above
interaction will be captured inside of mtcars2.


## Additional Functionality

In addition to the main `display()` function, the user can send any grid based 
plot to the browser as a JS interactive SVG.

```{r gridsvgjs_demo, eval=FALSE}
library(ggplot2)
data(mtcars)
qp <- qplot(mpg, data=mtcars, geom="density", fill=factor(cyl), alpha=I(.4))
gridsvgjs(qp)
```

There is an simplified, alternative (work-in-progress) function for 
ExpressionSet objects for the purpose of manually selecting a bicluster and 
obtaining a GO summary. 

```{r bicgo_demo, eval=FALSE}
data(expr)
bicgo(expr)
```

## Acknowledgments

Shiny <br/>
Joe Cheng and Winston Chang <br/>
http://www.rstudio.com/shiny/ <br/>

Force Layout <br/>
Jeff Allen <br/>
https://github.com/trestletech/shiny-sandbox/tree/master/grn <br/>

gridSVG <br/>
Simon Potter <br/>
http://sjp.co.nz/projects/gridsvg/ <br/>

Zoom/Pan JavaScript libraries <br/>
John Krauss <br/>
https://github.com/talos/jquery-svgpan <br/>
Andrea Leofreddi <br/>
https://code.google.com/p/svgpan/ <br/>

JavaScript Color Chooser <br/>
Jan Odvarko <br/>
http://jscolor.com/ <br/>

Data-Driven Documents <br/>
Michael Bostock <br/>
http://d3js.org/ <br/>

Javascript for returning values from data.frames <br/>
Kirill Savin <br/> 

Help with the display method for data.frames <br/>
Dan Tenenbaum <br/>
