Running Lightning without a server"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##
Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from lightning import Lightning\n",
"\n",
"from numpy import random"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Start local mode"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lightning was designed as a API-based visualization server, to which data is posted, and from which visualizations are returned. However, there are many use cases where operating without a server is desirable. For example, when doing data analysis locally, or when we're using notebooks like Jupyter."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For this use case, Lightning offers a \"local\" mode that doesn't require a server, or even internet access. This is a particularly easy way to get started with Lightning because it only requires a client installation! Once you've installed the Python client with `pip`, all you need to do is set local mode to true. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
Lightning initialized
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running local mode, some functionality limited.\n",
"\n"
]
}
],
"source": [
"lgn = Lightning(ipython=True, local=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Generate a plot"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then generate a plot. It'll automatically embed in the notebook (because we set `ipython=True`). Local plots are interactive just like plots rendered using the server! Try zooming and panning."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"
\n",
"\t
\n",
"\t\t
\n",
"\t\t\t\n",
"\t\t
\n",
"\t
\n",
"
\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"series = random.randn(5, 50)\n",
"\n",
"lgn.line(series)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Performance can often be a little better for local plots with large data sets, because there is no data transfer. "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"states = [\"NA\", \"AK\", \"AL\", \"AR\", \"AZ\", \"CA\", \"CO\",\"CT\",\n",
" \"DC\",\"DE\",\"FL\",\"GA\",\"HI\",\"IA\",\"ID\",\"IL\",\"IN\",\n",
" \"KS\",\"KY\",\"LA\",\"MA\",\"MD\",\"ME\",\"MI\",\"MN\",\"MO\",\n",
" \"MS\",\"MT\",\"NC\",\"ND\",\"NE\",\"NH\",\"NJ\",\"NM\",\"NV\",\n",
" \"NY\",\"OH\",\"OK\",\"OR\",\"PA\",\"RI\",\"SC\",\"SD\",\"TN\",\n",
" \"TX\",\"UT\",\"VA\",\"VI\",\"VT\",\"WA\",\"WI\",\"WV\",\"WY\"]\n",
"values = random.randn(len(states))\n",
"\n",
"lgn.map(states, values, colormap='Greens')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Saving to html"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also save a visualization to html, which is useful if you are using local mode without a notebook. First create the visualization."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"viz = lgn.scatter(random.randn(10), random.randn(10))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then save using `viz.save_html('filename')`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Limitations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Some visualizations are not available in local mode, for example, plots that use images (though we are working on expanding coverage)."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Plots of type 'image' not yet supported in local mode\n"
]
}
],
"source": [
"lgn.image(random.randn(25,25))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And although full interactivity is supported, there is currently no way to extract user selections from a visualization. For that, take a look at the various ways of running Lightning with a server! "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}