{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Publish a visualization from a private table\n", "\n", "This example illustrate how to publish a visualization using a private table. Using private tables requires to create Maps API keys for the visualization. By default it creates a custom Maps API key for all the private tables used in the visualization if not provided.\n", "\n", "Read more about Maps API Keys: https://carto.com/developers/auth-api/guides/types-of-API-Keys/\n", "\n", ">_Note: You'll need [CARTO Account](https://carto.com/signup) credentials to reproduce this example._" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from cartoframes.auth import set_default_credentials\n", "\n", "set_default_credentials('creds.json')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from cartoframes.viz import Map, Layer\n", "\n", "map_viz = Map(Layer('private_table'))" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The map has been published. The \"cartoframes_997c05771fd4e0916de49826722e51cd\" Maps API key with value \"7rj9ftFsOKUjSotnygh2jg\" is being used for the datasets: \"private_table\". You can manage your API keys on your account.\n" ] }, { "data": { "text/plain": [ "{'id': 'd5511e5e-f64f-4b87-b970-3ba7a36a62f1',\n", " 'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/d5511e5e-f64f-4b87-b970-3ba7a36a62f1',\n", " 'name': 'map_private_table',\n", " 'privacy': 'password'}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_viz.publish(\n", " name='map_private_table',\n", " password='1234',\n", " if_exists='replace')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Maps API key can be created in the CARTO Dashboard and provided to the method. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': 'd5511e5e-f64f-4b87-b970-3ba7a36a62f1',\n", " 'url': 'https://cartoframes-org.carto.com/u/cartoframes/kuviz/d5511e5e-f64f-4b87-b970-3ba7a36a62f1',\n", " 'name': 'map_private_table',\n", " 'privacy': 'password'}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_viz.publish(\n", " name='map_private_table',\n", " password='1234',\n", " if_exists='replace',\n", " maps_api_key='7rj9ftFsOKUjSotnygh2jg')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }