|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Using the JupyterLab Environment\n", |
| 8 | + "\n", |
| 9 | + "JupyterLab is a modern interactive development environment (IDE) that allows you to work with code, data, and the Jupyter notebook format. Starting with v1.5.0, the ArcGIS API for Python can be used in JupyterLab for a truly powerful development experience.\n", |
| 10 | + "\n", |
| 11 | + "-----\n", |
| 12 | + "\n", |
| 13 | + "\n", |
| 14 | + "\n", |
| 15 | + "-----\n", |
| 16 | + "\n", |
| 17 | + "\n", |
| 18 | + "JupyterLab builds upon all of the major components of the classic Jupyter Notebook experience (notebooks, terminal, text editor, file browser, ipywidgets, etc.) to create a flexible and powerful user experience. Click [here](https://blog.jupyter.org/jupyterlab-is-ready-for-users-5a6f039b8906) or [here](https://github.com/jupyterlab/jupyterlab) to read more about JupyterLab." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "metadata": {}, |
| 24 | + "source": [ |
| 25 | + "# Getting Started\n", |
| 26 | + "\n", |
| 27 | + "## Installation\n", |
| 28 | + "\n", |
| 29 | + "1. Install >=v1.5.0 of the ArcGIS API for Python in a new conda environment. Activate that environment.\n", |
| 30 | + "\n", |
| 31 | + "2. Run the following 2 commands:\n", |
| 32 | + "```\n", |
| 33 | + "jupyter labextension install @jupyter-widgets/jupyterlab-manager\n", |
| 34 | + "jupyter labextension install arcgis-map-ipywidget@1.5.0\n", |
| 35 | + "```\n", |
| 36 | + "\n", |
| 37 | + " - __IMPORTANT__: replace `1.5.0` with the _exact_ version number of the Python API you have installed.\n", |
| 38 | + " - You may need to have `npm` and/or `nodejs` installed on your computer and in this environment in order to succesfully complete this step.\n", |
| 39 | + "\n", |
| 40 | + "3. Now that you have set up the arcgis extensions, run `jupyter lab` from the same command prompt to launch an instance of JupyterLab." |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "markdown", |
| 45 | + "metadata": {}, |
| 46 | + "source": [ |
| 47 | + "## File Explorer\n", |
| 48 | + "\n", |
| 49 | + "Just like the classic Jupyter Notebook experience, JupyterLab offers a file explorer to open existing notebooks, create new notebooks, and organize your content. JupyterLab's file explorer is on the left pane of the main view.\n", |
| 50 | + "\n", |
| 51 | + "------\n", |
| 52 | + "\n", |
| 53 | + "\n", |
| 54 | + "\n", |
| 55 | + "------\n", |
| 56 | + "\n", |
| 57 | + "__JupyterLab interacts with the same .ipynb notebook format__. The only difference is the user interface, and the additions of some other external extensions." |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "markdown", |
| 62 | + "metadata": {}, |
| 63 | + "source": [ |
| 64 | + "## Using Windows and Tabs\n", |
| 65 | + "\n", |
| 66 | + "You may notice that Jupyter has a concept of 'windows' and 'tabs', unlike the classic Jupyter Notebook experience. This is a very powerful feature of JupyterLab: you can stack notebooks, place notebooks side by side, organize notebooks by tabs, etc. Simply click and drag any 'tab' as seen below:\n", |
| 67 | + "\n", |
| 68 | + "------\n", |
| 69 | + "\n", |
| 70 | + "\n", |
| 71 | + "\n", |
| 72 | + "------\n", |
| 73 | + "\n", |
| 74 | + "\n", |
| 75 | + "__Any window can be dragged like this__. JupyterLab lets you view and edit file types such as _.csv_, _.json_, etc. in new windows, as seen above." |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "markdown", |
| 80 | + "metadata": {}, |
| 81 | + "source": [ |
| 82 | + "## Using Cell Utilities\n", |
| 83 | + "\n", |
| 84 | + "Similar to the windows and tabs above, JupyterLab allows users to move cells in a notebook by dragging and dropping them. JupyterLab also supports dragging cells from one notebook to another notebook. Simply click the area to the left of the cell you want to move, and drag it wherever:\n", |
| 85 | + "\n", |
| 86 | + "-----\n", |
| 87 | + "\n", |
| 88 | + "\n", |
| 89 | + "\n", |
| 90 | + "-----\n", |
| 91 | + "\n", |
| 92 | + "JupyterLab also lets you select multiple cells by holding the _Shift_ key. You can move these cells as mentioned before, or right click and select 'Copy Cells' to copy them. JupyterLab has many options in their right click context menu worth exploring, including the 'Create New View For Output' option. This allows you to take __any__ cell output and duplicate it in a new window, allowing you to stack it, view it side-by-side, etc.\n", |
| 93 | + "\n", |
| 94 | + "-----\n", |
| 95 | + "\n", |
| 96 | + "\n", |
| 97 | + "\n", |
| 98 | + "------\n", |
| 99 | + "\n", |
| 100 | + "There are other cool things you can do with cells in JupyterLab not described in this guide, keep on exploring!" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "markdown", |
| 105 | + "metadata": {}, |
| 106 | + "source": [ |
| 107 | + "## Integration with the Map Widget\n", |
| 108 | + "\n", |
| 109 | + "v1.5.0 of the ArcGIS API for Python introduces many new exciting features for the Map Widget, including 2D rotation, 3D mode, 3D renderer support, and more. You can read [this guide page](../advanced-map-widget-useage) for more information about these other features of the new widget: this guide will highlight the map widget's seamless JupyterLab integration.\n", |
| 110 | + "\n", |
| 111 | + "-----\n", |
| 112 | + "\n", |
| 113 | + "\n", |
| 114 | + "\n", |
| 115 | + "----\n", |
| 116 | + "\n", |
| 117 | + "\n", |
| 118 | + "The `MapView` class's default view behavior is the same as in the classic Jupyter Notebook environment: the widget is displayed it in a cell's output area. However, you may notice a new UI button that is only visible in a JupyterLab environment:\n", |
| 119 | + "\n", |
| 120 | + "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gcUAAIIxu7mQQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAABI0lEQVRYw+1Wy3GDMBTch3JLBanA+TQR0gDz4JB0Y1xISkBAA4EqHOeYU6qAzYVkPAyWYSLii/Ymzb63q89qBAQEXBgyNamquYhs5zSw1v72SNOUp3gkd2VZ5uP5K1dzkrslqxnzRWQD4MVV4zQw5XguP8uyDckGwBeAm1M10Rrnqqq3fd+3JEVEYhc3WkMcQDMM46IoPv7NQJIkdyLS/oiXZXk4VxP5FDfGNEvEz17Cuciy7J7kGwB0XRfXdX0Yp+NoZ/waGMQbABzE35ekKfIkDhF5mhJf7Q6o6sOReFwUxd7BzdM0ffR5BALglaQAiK21eydZZEsSAFpfBkjy2Rhz7Vr5qimoqurTR4JWeYqDgWDAWwpUNb+ogbn/woCAgL/gG9knfWwKBGcvAAAAAElFTkSuQmC\"> \n", |
| 121 | + "\n", |
| 122 | + "By pressing this button, your widget will move from your cell's output area into a new window. This window can be tabbed, split, etc. like all other windows. If you want to restore the widget to the notebook it originated from, press this button:\n", |
| 123 | + "\n", |
| 124 | + "<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gcUAAYsnoHHlAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAABG0lEQVRYw+2WMVLDMBBF/9q+BBUlAS5hn8BeqQk1B8HcBgpLowtgnyJwGWtTkFAEOzIgkmHQLzXjeW9nV2sBKSn/PTR1yMwtET3EBInIo7W2PTwvQh9FqfJIMUcFpoy/E6XUrEB27hlIAkngxwJa65umaS7PIsDMt977gYie55ZaKMXM4hhEJFi5iLy87yu5ByDRBIwxA4AhAO93spUxZnOyFtR1fb2rHERUdV23iT6ESqmSmdspeJ7nfSz4rICIlIc/EGZe7eHjOEaBL24BM68AfMCdc6+x9kDxFbiIlM65t5MtIq311R4OoLLWRoUHBUSkJyLJsqz8DfiSFlwAePLe3zHz5ENl6rZEnQEAa6JPW7Zd8txKSfkT2QKASXQbvOVu9AAAAABJRU5ErkJggg==\">\n", |
| 125 | + "\n", |
| 126 | + "Try this for yourself! If you're reading this guide in a JupyterLab setting, run the below cell:" |
| 127 | + ] |
| 128 | + }, |
| 129 | + { |
| 130 | + "cell_type": "code", |
| 131 | + "execution_count": null, |
| 132 | + "metadata": {}, |
| 133 | + "outputs": [], |
| 134 | + "source": [ |
| 135 | + "from arcgis.gis import GIS\n", |
| 136 | + "\n", |
| 137 | + "#Create a map widget like you have done many times before\n", |
| 138 | + "gis = GIS()\n", |
| 139 | + "map = gis.map()\n", |
| 140 | + "map" |
| 141 | + ] |
| 142 | + }, |
| 143 | + { |
| 144 | + "cell_type": "markdown", |
| 145 | + "metadata": {}, |
| 146 | + "source": [ |
| 147 | + "### WebMaps and WebScenes\n", |
| 148 | + "\n", |
| 149 | + "WebMap and WebScene Objects include this same UI button: run the two below cells to try for yourself!" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "code", |
| 154 | + "execution_count": null, |
| 155 | + "metadata": {}, |
| 156 | + "outputs": [], |
| 157 | + "source": [ |
| 158 | + "from arcgis.mapping import WebMap\n", |
| 159 | + "webmap_item = gis.content.get(\"ab42b088573d4253a22a8b38ee698ccd\")\n", |
| 160 | + "webmap = WebMap(webmap_item)\n", |
| 161 | + "webmap" |
| 162 | + ] |
| 163 | + }, |
| 164 | + { |
| 165 | + "cell_type": "code", |
| 166 | + "execution_count": null, |
| 167 | + "metadata": {}, |
| 168 | + "outputs": [], |
| 169 | + "source": [ |
| 170 | + "from arcgis.mapping import WebScene\n", |
| 171 | + "webscene_item = gis.content.get(\"421433baeb8d487b903d4a89df79149b\")\n", |
| 172 | + "webscene = WebScene(webscene_item)\n", |
| 173 | + "webscene" |
| 174 | + ] |
| 175 | + }, |
| 176 | + { |
| 177 | + "cell_type": "markdown", |
| 178 | + "metadata": {}, |
| 179 | + "source": [ |
| 180 | + "### Controlling New Windows Programatically\n", |
| 181 | + "\n", |
| 182 | + "Although you just drove this cool new window functionality with your mouse, you still are using __Python__: what sort of Python API would this be if we didn't provide you the option to control this functionality programmatically?!\n", |
| 183 | + "\n", |
| 184 | + "Each instances of a `MapView` widget has a `tab_mode` property and a `toggle_window_view()` method. Setting `tab_mode` will change how the map widget goes into a new window. Try running the below cells to experiment with this behavior:" |
| 185 | + ] |
| 186 | + }, |
| 187 | + { |
| 188 | + "cell_type": "code", |
| 189 | + "execution_count": null, |
| 190 | + "metadata": {}, |
| 191 | + "outputs": [], |
| 192 | + "source": [ |
| 193 | + "#First, draw a map\n", |
| 194 | + "map = gis.map()\n", |
| 195 | + "map" |
| 196 | + ] |
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "code", |
| 200 | + "execution_count": null, |
| 201 | + "metadata": {}, |
| 202 | + "outputs": [], |
| 203 | + "source": [ |
| 204 | + "#Set the tab mode to one of the below options, run the cell, then press the 'new window' button\n", |
| 205 | + "#map.tab_mode = \"split-bottom\"\n", |
| 206 | + "#map.tab_mode = \"split-right\"\n", |
| 207 | + "#map.tab_mode = \"auto\"\n", |
| 208 | + "#map.tab_mode = \"tab-after\"" |
| 209 | + ] |
| 210 | + }, |
| 211 | + { |
| 212 | + "cell_type": "markdown", |
| 213 | + "metadata": {}, |
| 214 | + "source": [ |
| 215 | + "After a map is displayed, you can call the `toggle_window_view()` method to move the map to a new window. You can then call this method while the widget is already in a new window to restore the widget to the original notebook. (i.e., each call to this method is the functional equivalent of pressing the button). Try running the below cells:" |
| 216 | + ] |
| 217 | + }, |
| 218 | + { |
| 219 | + "cell_type": "code", |
| 220 | + "execution_count": null, |
| 221 | + "metadata": {}, |
| 222 | + "outputs": [], |
| 223 | + "source": [ |
| 224 | + "from arcgis.widgets import MapView\n", |
| 225 | + "#First, draw a map\n", |
| 226 | + "map = MapView(gis=gis)\n", |
| 227 | + "map" |
| 228 | + ] |
| 229 | + }, |
| 230 | + { |
| 231 | + "cell_type": "code", |
| 232 | + "execution_count": null, |
| 233 | + "metadata": {}, |
| 234 | + "outputs": [], |
| 235 | + "source": [ |
| 236 | + "#Run this cell a few times in a row\n", |
| 237 | + "map.toggle_window_view()" |
| 238 | + ] |
| 239 | + }, |
| 240 | + { |
| 241 | + "cell_type": "markdown", |
| 242 | + "metadata": {}, |
| 243 | + "source": [ |
| 244 | + "You can also programatically specify the `title` (text displayed on the tab) and `tab_mode` in each method call:" |
| 245 | + ] |
| 246 | + }, |
| 247 | + { |
| 248 | + "cell_type": "code", |
| 249 | + "execution_count": null, |
| 250 | + "metadata": {}, |
| 251 | + "outputs": [], |
| 252 | + "source": [ |
| 253 | + "#First, draw a map\n", |
| 254 | + "map = gis.map(mode=\"3D\")\n", |
| 255 | + "map" |
| 256 | + ] |
| 257 | + }, |
| 258 | + { |
| 259 | + "cell_type": "code", |
| 260 | + "execution_count": null, |
| 261 | + "metadata": {}, |
| 262 | + "outputs": [], |
| 263 | + "source": [ |
| 264 | + "#Run this cell to move it in a new window\n", |
| 265 | + "map.toggle_window_view(title=\"My 3D Map\", tab_mode=\"split-top\")" |
| 266 | + ] |
| 267 | + }, |
| 268 | + { |
| 269 | + "cell_type": "code", |
| 270 | + "execution_count": null, |
| 271 | + "metadata": {}, |
| 272 | + "outputs": [], |
| 273 | + "source": [ |
| 274 | + "#Then, run this cell to move it back to the notebook\n", |
| 275 | + "map.toggle_window_view()" |
| 276 | + ] |
| 277 | + }, |
| 278 | + { |
| 279 | + "cell_type": "code", |
| 280 | + "execution_count": null, |
| 281 | + "metadata": {}, |
| 282 | + "outputs": [], |
| 283 | + "source": [ |
| 284 | + "#Run this cell to cycle through all tab_modes\n", |
| 285 | + "tab_modes = ['auto', 'split-top' 'split-bottom', 'split-left',\n", |
| 286 | + " 'split-right', 'tab-before', 'tab-after']\n", |
| 287 | + "for tab_mode in tab_modes:\n", |
| 288 | + " #to new window\n", |
| 289 | + " map.toggle_window_view(title=tab_mode, tab_mode=tab_mode)\n", |
| 290 | + " time.sleep(4)\n", |
| 291 | + " #to original notebook\n", |
| 292 | + " map.toggle_window_view()\n", |
| 293 | + " time.sleep(4)" |
| 294 | + ] |
| 295 | + }, |
| 296 | + { |
| 297 | + "cell_type": "markdown", |
| 298 | + "metadata": {}, |
| 299 | + "source": [ |
| 300 | + "This functionality can be very powerful in many ways: Say you have a list of 3 or more WebScene items, and you want to display them all in new tabs in 1 cell call. You would write something like this:" |
| 301 | + ] |
| 302 | + }, |
| 303 | + { |
| 304 | + "cell_type": "code", |
| 305 | + "execution_count": null, |
| 306 | + "metadata": {}, |
| 307 | + "outputs": [], |
| 308 | + "source": [ |
| 309 | + "#Run this cell, it works!\n", |
| 310 | + "from arcgis.gis import GIS\n", |
| 311 | + "from arcgis.widgets import MapView\n", |
| 312 | + "gis = GIS()\n", |
| 313 | + "for webscene_id in ['31874da8a16d45bfbc1273422f772270',\n", |
| 314 | + " '91b46c2b162c48dba264b2190e1dbcff',\n", |
| 315 | + " '46c47340708f446ba7f112f139e8ae5e']:\n", |
| 316 | + " webscene_item = gis.content.get(webscene_id)\n", |
| 317 | + " map = MapView(gis=gis, item=webscene_item, mode=\"3D\") \n", |
| 318 | + " map.toggle_window_view(title=webscene_item.title, tab_mode='tab-after')" |
| 319 | + ] |
| 320 | + }, |
| 321 | + { |
| 322 | + "cell_type": "markdown", |
| 323 | + "metadata": {}, |
| 324 | + "source": [ |
| 325 | + "\n", |
| 326 | + "See [the API reference](https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.widgets.html#arcgis.widgets.MapView.toggle_window_view) for more information on programatic control of the Map Widget." |
| 327 | + ] |
| 328 | + }, |
| 329 | + { |
| 330 | + "cell_type": "markdown", |
| 331 | + "metadata": {}, |
| 332 | + "source": [ |
| 333 | + "# Conclusion\n", |
| 334 | + "\n", |
| 335 | + "JupyterLab implements many features you can leverage right now to make the most of your experience with the ArcGIS API for Python. Try it out, and please [leave us a comment, suggest a feature, or report a bug](https://github.com/Esri/arcgis-python-api/issues/new)! We look forward to seeing what you will create in JupyterLab!" |
| 336 | + ] |
| 337 | + } |
| 338 | + ], |
| 339 | + "metadata": { |
| 340 | + "kernelspec": { |
| 341 | + "display_name": "Python 3", |
| 342 | + "language": "python", |
| 343 | + "name": "python3" |
| 344 | + }, |
| 345 | + "language_info": { |
| 346 | + "codemirror_mode": { |
| 347 | + "name": "ipython", |
| 348 | + "version": 3 |
| 349 | + }, |
| 350 | + "file_extension": ".py", |
| 351 | + "mimetype": "text/x-python", |
| 352 | + "name": "python", |
| 353 | + "nbconvert_exporter": "python", |
| 354 | + "pygments_lexer": "ipython3", |
| 355 | + "version": "3.6.5" |
| 356 | + } |
| 357 | + }, |
| 358 | + "nbformat": 4, |
| 359 | + "nbformat_minor": 2 |
| 360 | +} |
0 commit comments