diff --git a/vizro-core/examples/jupyter/app.ipynb b/vizro-core/examples/jupyter/app.ipynb index 3879c378b..54820dbef 100644 --- a/vizro-core/examples/jupyter/app.ipynb +++ b/vizro-core/examples/jupyter/app.ipynb @@ -3,7 +3,11 @@ { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "import pandas as pd\n", @@ -18,541 +22,217 @@ { "cell_type": "code", "execution_count": 2, + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from dotenv import load_dotenv\n", + "load_dotenv()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, + "pycharm": { + "name": "#%%\n" + }, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: https://lingyi_zhang%40mckinsey.com:****@mckinsey.jfrog.io/artifactory/api/pypi/c1eng-pypi-local/simple, https://lingyi_zhang%40mckinsey.com:****@mckinsey.jfrog.io/artifactory/api/pypi/python/simple\n", + "Collecting boto3\n", + " Downloading https://mckinsey.jfrog.io/artifactory/api/pypi/python/packages/packages/12/57/163578282770fd613a159267f6b3da7cde24a2ad9d35ddad019dc0a6f9e5/boto3-1.29.1-py3-none-any.whl (135 kB)\n", + "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m135.8/135.8 kB\u001B[0m \u001B[31m2.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m\n", + "\u001B[?25hCollecting botocore<1.33.0,>=1.32.1 (from boto3)\n", + " Downloading https://mckinsey.jfrog.io/artifactory/api/pypi/python/packages/packages/f2/35/06b52c153f61ac20c3b70c1e2c20a94687b861762f8520bd69308710c1ee/botocore-1.32.1-py3-none-any.whl (11.4 MB)\n", + "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m11.4/11.4 MB\u001B[0m \u001B[31m32.6 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\n", + "\u001B[?25hRequirement already satisfied: jmespath<2.0.0,>=0.7.1 in /Users/lingyi_zhang/Library/Application Support/hatch/env/virtual/vizx-hyphen-ai/l4ttxbXh/vizx-hyphen-ai/lib/python3.9/site-packages (from boto3) (1.0.1)\n", + "Collecting s3transfer<0.8.0,>=0.7.0 (from boto3)\n", + " Downloading https://mckinsey.jfrog.io/artifactory/api/pypi/python/s3transfer-0.7.0-py3-none-any.whl (79 kB)\n", + "\u001B[2K \u001B[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001B[0m \u001B[32m79.8/79.8 kB\u001B[0m \u001B[31m1.5 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0ma \u001B[36m0:00:01\u001B[0m\n", + "\u001B[?25hRequirement already satisfied: python-dateutil<3.0.0,>=2.1 in /Users/lingyi_zhang/Library/Application Support/hatch/env/virtual/vizx-hyphen-ai/l4ttxbXh/vizx-hyphen-ai/lib/python3.9/site-packages (from botocore<1.33.0,>=1.32.1->boto3) (2.8.2)\n", + "Collecting urllib3<1.27,>=1.25.4 (from botocore<1.33.0,>=1.32.1->boto3)\n", + " Using cached https://mckinsey.jfrog.io/artifactory/api/pypi/python/urllib3-1.26.18-py2.py3-none-any.whl (143 kB)\n", + "Requirement already satisfied: six>=1.5 in /Users/lingyi_zhang/Library/Application Support/hatch/env/virtual/vizx-hyphen-ai/l4ttxbXh/vizx-hyphen-ai/lib/python3.9/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<1.33.0,>=1.32.1->boto3) (1.16.0)\n", + "Installing collected packages: urllib3, botocore, s3transfer, boto3\n", + " Attempting uninstall: urllib3\n", + " Found existing installation: urllib3 2.0.7\n", + " Uninstalling urllib3-2.0.7:\n", + " Successfully uninstalled urllib3-2.0.7\n", + "Successfully installed boto3-1.29.1 botocore-1.32.1 s3transfer-0.7.0 urllib3-1.26.18\n", + "\n", + "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m23.1.2\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m23.3.1\u001B[0m\n", + "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\n" + ] + } + ], + "source": [ + "!pip install boto3" + ] + }, + { + "cell_type": "code", + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ - "def retrieve_avg_continent_data():\n", - " \"\"\"This is function returns gapminder data grouped by continent.\"\"\"\n", - " df = px.data.gapminder()\n", - " mean = (\n", - " df.groupby(by=[\"continent\", \"year\"]).agg({\"lifeExp\": \"mean\", \"pop\": \"mean\", \"gdpPercap\": \"mean\"}).reset_index()\n", - " )\n", - " return mean\n", - "\n", - "\n", - "def create_variable_analysis():\n", - " \"\"\"Function returns a page with gapminder data to do variable analysis.\"\"\"\n", - " df_gapminder = px.data.gapminder()\n", - " df_avg_gapminder = retrieve_avg_continent_data()\n", - "\n", - " page_variable = vm.Page(\n", - " title=\"Variable Analysis\",\n", - " layout=vm.Layout(\n", - " grid=[\n", - " # fmt: off\n", - " [0, 1, 1, 1],\n", - " [2, 3, 3, 3],\n", - " [4, 5, 5, 5],\n", - " [6, 7, 7, 7],\n", - " # fmt: on\n", - " ],\n", - " row_min_height=\"400px\",\n", - " row_gap=\"25px\",\n", - " ),\n", - " components=[\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Overview\n", - " The world map provides initial insights into the variations of metrics across countries and\n", - " continents. Click on Play to see the animation and explore the development over time.\n", - "\n", - " #### Observation\n", - " A global trend of increasing life expectancy emerges, with some exceptions in specific African\n", - " countries. Additionally, despite similar population growth rates across continents, the overall\n", - " global population continues to expand, with India and China leading the way. Meanwhile, GDP per\n", - " capita experiences growth in most regions.\n", - "\n", - " \"\"\"\n", - " ),\n", - " vm.Graph(\n", - " id=\"variable_map\",\n", - " figure=px.choropleth(\n", - " df_gapminder,\n", - " locations=\"iso_alpha\",\n", - " color=\"lifeExp\",\n", - " hover_name=\"country\",\n", - " animation_frame=\"year\",\n", - " labels={\n", - " \"year\": \"year\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"pop\": \"Population\",\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " },\n", - " title=\"Global development over time\",\n", - " ),\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Distribution\n", - " The boxplot illustrates the distribution of each metric across continents, facilitating comparisons\n", - " of life expectancy, GDP per capita, and population statistics.\n", - "\n", - " Observations reveal that Europe and Oceania have the highest life expectancy and GDP per capita,\n", - " likely influenced by their smaller population growth. Additionally, Asia and America exhibit\n", - " notable GDP per capita outliers, indicating variations among countries within these continents or\n", - " large growth over the observed years.\n", - " \"\"\"\n", - " ),\n", - " vm.Graph(\n", - " id=\"variable_boxplot\",\n", - " figure=px.box(\n", - " df_gapminder,\n", - " x=\"continent\",\n", - " y=\"lifeExp\",\n", - " color=\"continent\",\n", - " labels={\n", - " \"year\": \"year\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"pop\": \"Population\",\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " \"continent\": \"Continent\",\n", - " },\n", - " title=\"Distribution per continent\",\n", - " color_discrete_map={\n", - " \"Africa\": \"#00b4ff\",\n", - " \"Americas\": \"#ff9222\",\n", - " \"Asia\": \"#3949ab\",\n", - " \"Europe\": \"#ff5267\",\n", - " \"Oceania\": \"#08bdba\",\n", - " },\n", - " ),\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Development\n", - " The line chart tracks the variable's progress from 1952 to 2007, facilitating a deeper comprehension\n", - " of each metric.\n", - "\n", - " #### Observation\n", - " Oceania and Europe are found to have the highest total GDP per capita and exhibit significant\n", - " growth. In contrast, Asia, Africa, and America demonstrate a more pronounced upward trend in\n", - " population increase compared to Europe and Oceania, suggesting that GDP per capita growth might be\n", - " influenced by relatively smaller population growth in the latter two continents.\n", - "\n", - " \"\"\"\n", - " ),\n", - " vm.Graph(\n", - " id=\"variable_line\",\n", - " figure=px.line(\n", - " df_avg_gapminder,\n", - " y=\"lifeExp\",\n", - " x=\"year\",\n", - " color=\"continent\",\n", - " title=\"Development between 1952 and 2007\",\n", - " labels={\n", - " \"year\": \"Year\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"pop\": \"Population\",\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " \"continent\": \"Continent\",\n", - " },\n", - " color_discrete_map={\n", - " \"Africa\": \"#00b4ff\",\n", - " \"Americas\": \"#ff9222\",\n", - " \"Asia\": \"#3949ab\",\n", - " \"Europe\": \"#ff5267\",\n", - " \"Oceania\": \"#08bdba\",\n", - " },\n", - " ),\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Recent status\n", - " Examining the data for 2007 provides insight into the current status of each continent and metrics.\n", - "\n", - " #### Observation\n", - " Asia held the largest population, followed by America, Europe, Africa, and Oceania. Life expectancy\n", - " surpassed 70 years for all continents, except Africa with 55 years. GDP per capita aligns with\n", - " earlier findings, with Oceania and Europe reporting the highest values and Africa recording the\n", - " lowest.\n", - " \"\"\"\n", - " ),\n", - " vm.Graph(\n", - " id=\"variable_bar\",\n", - " figure=px.bar(\n", - " df_avg_gapminder.query(\"year == 2007\"),\n", - " x=\"lifeExp\",\n", - " y=\"continent\",\n", - " orientation=\"h\",\n", - " title=\"Comparison of average metric for 2007\",\n", - " labels={\n", - " \"year\": \"year\",\n", - " \"continent\": \"Continent\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"pop\": \"Population\",\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " },\n", - " color=\"continent\",\n", - " color_discrete_map={\n", - " \"Africa\": \"#00b4ff\",\n", - " \"Americas\": \"#ff9222\",\n", - " \"Asia\": \"#3949ab\",\n", - " \"Europe\": \"#ff5267\",\n", - " \"Oceania\": \"#08bdba\",\n", - " },\n", - " ),\n", - " ),\n", - " ],\n", - " controls=[\n", - " vm.Parameter(\n", - " targets=[\"variable_map.color\", \"variable_boxplot.y\", \"variable_line.y\", \"variable_bar.x\"],\n", - " selector=vm.RadioItems(options=[\"lifeExp\", \"pop\", \"gdpPercap\"], title=\"Select variable\"),\n", - " )\n", - " ],\n", - " )\n", - " return page_variable\n", - "\n", - "\n", - "def create_relation_analysis():\n", - " \"\"\"Function returns a page to perform relation analysis.\"\"\"\n", - " df_gapminder = px.data.gapminder()\n", - "\n", - " page_relation_analysis = vm.Page(\n", - " title=\"Relationship Analysis\",\n", - " layout=vm.Layout(\n", - " grid=[[0, 0, 0, 0, 1]] + [[2, 2, 3, 3, 3]] * 4 + [[4, 4, 4, 4, 4]] * 5,\n", - " row_min_height=\"100px\",\n", - " row_gap=\"24px\",\n", - " ),\n", - " components=[\n", - " vm.Card(\n", - " text=\"\"\"\n", - " Population, GDP per capita, and life expectancy are interconnected metrics that provide insights\n", - " into the socio-economic well-being of a country.\n", - " Rapid population growth can strain resources and infrastructure, impacting GDP per capita. Higher\n", - " GDP per capita often enables better healthcare and improved life expectancy, but other factors such\n", - " as healthcare quality and social policies also play significant roles.\n", - " \"\"\"\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " #### Last updated\n", - " July, 2023\n", - " \"\"\"\n", - " ),\n", - " vm.Graph(\n", - " id=\"bar_relation_2007\",\n", - " figure=px.box(\n", - " df_gapminder.query(\"year == 2007\"),\n", - " x=\"continent\",\n", - " y=\"lifeExp\",\n", - " color=\"continent\",\n", - " hover_name=\"continent\",\n", - " title=\"Relationship in 2007\",\n", - " labels={\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " \"pop\": \"Population\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"continent\": \"Continent\",\n", - " },\n", - " color_discrete_map={\n", - " \"Africa\": \"#00b4ff\",\n", - " \"Americas\": \"#ff9222\",\n", - " \"Asia\": \"#3949ab\",\n", - " \"Europe\": \"#ff5267\",\n", - " \"Oceania\": \"#08bdba\",\n", - " },\n", - " custom_data=[\"continent\"],\n", - " ),\n", - " actions=[vm.Action(function=filter_interaction(targets=[\"scatter_relation_2007\"]))],\n", - " ),\n", - " vm.Graph(\n", - " id=\"scatter_relation_2007\",\n", - " figure=px.scatter(\n", - " df_gapminder.query(\"year == 2007\"),\n", - " x=\"gdpPercap\",\n", - " y=\"lifeExp\",\n", - " size=\"pop\",\n", - " color=\"continent\",\n", - " hover_name=\"country\",\n", - " size_max=60,\n", - " labels={\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " \"pop\": \"Population\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"continent\": \"Continent\",\n", - " },\n", - " color_discrete_map={\n", - " \"Africa\": \"#00b4ff\",\n", - " \"Americas\": \"#ff9222\",\n", - " \"Asia\": \"#3949ab\",\n", - " \"Europe\": \"#ff5267\",\n", - " \"Oceania\": \"#08bdba\",\n", - " },\n", - " ),\n", - " ),\n", - " vm.Graph(\n", - " id=\"scatter_relation\",\n", - " figure=px.scatter(\n", - " df_gapminder,\n", - " x=\"gdpPercap\",\n", - " y=\"lifeExp\",\n", - " animation_frame=\"year\",\n", - " animation_group=\"country\",\n", - " size=\"pop\",\n", - " color=\"continent\",\n", - " hover_name=\"country\",\n", - " facet_col=\"continent\",\n", - " labels={\n", - " \"gdpPercap\": \"GDP per capita\",\n", - " \"pop\": \"Population\",\n", - " \"lifeExp\": \"Life expectancy\",\n", - " \"continent\": \"Continent\",\n", - " },\n", - " range_y=[25, 90],\n", - " color_discrete_map={\n", - " \"Africa\": \"#00b4ff\",\n", - " \"Americas\": \"#ff9222\",\n", - " \"Asia\": \"#3949ab\",\n", - " \"Europe\": \"#ff5267\",\n", - " \"Oceania\": \"#08bdba\",\n", - " },\n", - " ),\n", - " ),\n", - " ],\n", - " controls=[\n", - " vm.Parameter(\n", - " targets=[\"scatter_relation_2007.x\", \"scatter_relation.x\"],\n", - " selector=vm.Dropdown(\n", - " options=[\"lifeExp\", \"gdpPercap\", \"pop\"], multi=False, value=\"gdpPercap\", title=\"Choose x-axis\"\n", - " ),\n", - " ),\n", - " vm.Parameter(\n", - " targets=[\"scatter_relation_2007.y\", \"scatter_relation.y\", \"bar_relation_2007.y\"],\n", - " selector=vm.Dropdown(\n", - " options=[\"lifeExp\", \"gdpPercap\", \"pop\"], multi=False, value=\"lifeExp\", title=\"Choose y-axis\"\n", - " ),\n", - " ),\n", - " vm.Parameter(\n", - " targets=[\"scatter_relation_2007.size\", \"scatter_relation.size\"],\n", - " selector=vm.Dropdown(\n", - " options=[\"lifeExp\", \"gdpPercap\", \"pop\"], multi=False, value=\"pop\", title=\"Choose bubble size\"\n", - " ),\n", - " ),\n", - " ],\n", - " )\n", - " return page_relation_analysis\n", - "\n", - "\n", - "def create_continent_summary():\n", - " \"\"\"Function returns a page with markdown including images.\"\"\"\n", - " page_summary = vm.Page(\n", - " title=\"Continent Summary\",\n", - " layout=vm.Layout(grid=[[i] for i in range(5)], row_min_height=\"190px\", row_gap=\"25px\"),\n", - " components=[\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Africa\n", - " ![](assets/images/continents/africa.svg#my-image)\n", - "\n", - " Africa, a diverse and expansive continent, faces both challenges and progress in its socio-economic\n", - " landscape. In 2007, Africa's GDP per capita was approximately $3,000, reflecting relatively slower\n", - " growth compared to other continents like Oceania and Europe.\n", - "\n", - " However, Africa has shown notable improvements in life expectancy over time, reaching 55 years in\n", - " 2007. Despite these economic disparities, Africa's population has been steadily increasing,\n", - " reflecting its significant potential for development.\n", - " \"\"\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Americas\n", - " ![](assets/images/continents/america.svg#my-image)\n", - "\n", - " Comprising North and South America, Americas represents a region of vast geographical and cultural\n", - " diversity. In 2007, the continent experienced substantial population growth, with a diverse mix of\n", - " countries contributing to this expansion.\n", - "\n", - " Although its GDP per capita of $11,000 in 2007 exhibited variations across countries, America\n", - " maintained similar levels to Asia, reflecting its economic significance. With North America\n", - " generally reporting higher life expectancy compared to South America, America remains a region of\n", - " opportunities and challenges.\n", - " \"\"\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Asia\n", - " ![](assets/images/continents/asia.svg#my-image)\n", - "\n", - " Asia holds a central role in the global economy. It's growth in GDP per capita to $12,000 in 2007\n", - " and population has been significant, outpacing many other continents. In 2007, it boasted the\n", - " highest population among all continents, with countries like China and India leading the way.\n", - "\n", - " Despite facing various socio-economic challenges, Asia's increasing life expectancy from 46 years\n", - " to 70 over the years reflects advancements in healthcare and overall well-being, making it a vital\n", - " region driving global progress and development.\n", - " \"\"\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Europe\n", - " ![](assets/images/continents/europe.svg#my-image)\n", + "import boto3\n", "\n", - " Europe boasts a strong and thriving economy. In 2007, it exhibited the second-highest GDP per\n", - " capita of $25,000 among continents, indicating sustained economic growth and development.\n", - "\n", - " Europe's life expectancy surpassed 75 years, showcasing a high standard of living and\n", - " well-established healthcare systems. With its robust infrastructure, advanced industries, and\n", - " quality of life, Europe continues to be a leading force in the global economy. Between 1952 and\n", - " 2007, Europe's population experienced moderate growth, with a factor of approximately 1.5,\n", - " notably lower compared to other continents like Asia and America.\n", - " \"\"\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ### Oceania\n", - " ![](assets/images/continents/oceania.svg#my-image)\n", - "\n", - " Oceania, comprising countries like Australia and New Zealand, stands out with notable economic\n", - " prosperity and longer life expectancy. In 2007, it boasted the highest GDP per capita of $27,000\n", - " among continents and exhibited one of the highest life expectancy levels, surpassing 80 years.\n", - "\n", - " Despite a relatively smaller population size, Oceania's strong economic growth has contributed\n", - " to improved living standards and overall well-being of its population.\n", - " \"\"\",\n", - " ),\n", - " ],\n", - " )\n", - " return page_summary\n", - "\n", - "\n", - "def create_country_analysis():\n", - " \"\"\"Function returns a page to perform analysis on country level.\"\"\"\n", - " df_gapminder = px.data.gapminder()\n", - "\n", - " df_gapminder_agg = px.data.gapminder()\n", - " df_gapminder_agg[\"lifeExp\"] = df_gapminder_agg.groupby(by=[\"continent\", \"year\"])[\"lifeExp\"].transform(\"mean\")\n", - " df_gapminder_agg[\"gdpPercap\"] = df_gapminder_agg.groupby(by=[\"continent\", \"year\"])[\"gdpPercap\"].transform(\"mean\")\n", - " df_gapminder_agg[\"pop\"] = df_gapminder_agg.groupby(by=[\"continent\", \"year\"])[\"pop\"].transform(\"sum\")\n", - "\n", - " df_gapminder[\"data\"] = \"Country\"\n", - " df_gapminder_agg[\"data\"] = \"Continent\"\n", - "\n", - " df_gapminder = pd.concat([df_gapminder_agg, df_gapminder], ignore_index=True)\n", - "\n", - " page_country = vm.Page(\n", - " title=\"Country Analysis\",\n", - " layout=vm.Layout(grid=[[0, 0, 0, 1, 1, 1]] * 7 + [[2, 2, 2, 2, 2, 2]]),\n", - " components=[\n", - " vm.Graph(\n", - " id=\"bar_country\",\n", - " figure=px.bar(\n", - " df_gapminder,\n", - " x=\"year\",\n", - " y=\"pop\",\n", - " color=\"data\",\n", - " barmode=\"group\",\n", - " labels={\"year\": \"Year\", \"data\": \"Data\", \"pop\": \"Population\"},\n", - " color_discrete_map={\"Country\": \"#afe7f9\", \"Continent\": \"#003875\"},\n", - " ),\n", - " ),\n", - " vm.Graph(\n", - " id=\"line_country\",\n", - " figure=px.line(\n", - " df_gapminder,\n", - " x=\"year\",\n", - " y=\"gdpPercap\",\n", - " color=\"data\",\n", - " labels={\"year\": \"Year\", \"data\": \"Data\", \"gdpPercap\": \"GDP per capita\"},\n", - " color_discrete_map={\"Country\": \"#afe7f9\", \"Continent\": \"#003875\"},\n", - " markers=True,\n", - " ),\n", - " ),\n", - " vm.Button(\n", - " text=\"Export data\",\n", - " actions=[\n", - " vm.Action(\n", - " function=export_data(\n", - " targets=[\"bar_country\"],\n", - " )\n", - " ),\n", - " ],\n", - " ),\n", - " ],\n", - " controls=[\n", - " vm.Filter(column=\"country\", selector=vm.Dropdown(value=\"India\", multi=False, title=\"Select country\")),\n", - " vm.Filter(column=\"year\", selector=vm.RangeSlider(title=\"Select timeframe\"))\n", - " ],\n", - " )\n", - " return page_country\n", - "\n", - "\n", - "def create_home_page():\n", - " \"\"\"Function returns the homepage.\"\"\"\n", - " page_home = vm.Page(\n", - " title=\"Homepage\",\n", - " layout=vm.Layout(grid=[[0, 1], [2, 3]], row_gap=\"16px\", col_gap=\"24px\"),\n", - " components=[\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ![](assets/images/icons/content/hypotheses.svg#icon-top)\n", - "\n", - " ### Variable Analysis\n", - "\n", - " Analyzing population, GDP per capita and life expectancy on country and continent level.\n", - " \"\"\",\n", - " href=\"/variable-analysis\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ![](assets/images/icons/content/hypotheses.svg#icon-top)\n", - "\n", - " ### Relationship Analysis\n", - "\n", - " Investigating the interconnection between population, GDP per capita and life expectancy.\n", - " \"\"\",\n", - " href=\"/relationship-analysis\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ![](assets/images/icons/content/collections.svg#icon-top)\n", - "\n", - " ### Continent Summary\n", - "\n", - " Summarizing the main findings for each continent.\n", - " \"\"\",\n", - " href=\"/continent-summary\",\n", - " ),\n", - " vm.Card(\n", - " text=\"\"\"\n", - " ![](assets/images/icons/content/features.svg#icon-top)\n", - "\n", - " ### Country Analysis\n", - "\n", - " Discovering how the metrics differ for each country and export data for further investigation.\n", - " \"\"\",\n", - " href=\"/country-analysis\",\n", - " ),\n", - " ],\n", - " )\n", - " return page_home" + "# Let's use Amazon S3\n", + "s3_resource = boto3.resource('s3')" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "cortex-kedroservice-demo-bucket\n" + ] + } + ], "source": [ - "dashboard = vm.Dashboard(\n", - " pages=[\n", - " create_home_page(),\n", - " create_variable_analysis(),\n", - " create_relation_analysis(),\n", - " create_continent_summary(),\n", - " create_country_analysis(),\n", - " ]\n", + "# Print out bucket names\n", + "for bucket in s3_resource.buckets.all():\n", + " print(bucket.name)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " row_id transaction_date transaction_year customer_level_3 \\\n", + "0 1 2019-03-29 2019 Customer ID 10 \n", + "1 2 2019-04-06 2019 Customer ID 7 \n", + "2 3 2019-12-25 2019 Customer ID 8 \n", + "3 4 2019-08-31 2019 Customer ID 1 \n", + "4 5 2019-01-18 2019 Customer ID 8 \n", + "... ... ... ... ... \n", + "1179 1180 2021-02-20 2020 Customer ID 3 \n", + "1180 1181 2021-02-21 2020 Customer ID 10 \n", + "1181 1182 2021-02-22 2020 Customer ID 7 \n", + "1182 1183 2021-02-23 2020 Customer ID 1 \n", + "1183 1184 2021-02-24 2020 Customer ID 3 \n", + "\n", + " customer_level_2 product_level_4 product_level_3 geo_level_3 \\\n", + "0 Customer group 2 Product ID 7 Product group 2 Belgium \n", + "1 Customer group 2 Product ID 9 Product group 2 Italy \n", + "2 Customer group 2 Product ID 7 Product group 2 Italy \n", + "3 Customer group 1 Product ID 1 Product group 1 Spain \n", + "4 Customer group 2 Product ID 3 Product group 1 France \n", + "... ... ... ... ... \n", + "1179 Customer group 1 Product ID 6 Product group 2 France \n", + "1180 Customer group 2 Product ID 9 Product group 2 Belgium \n", + "1181 Customer group 2 Product ID 10 Product group 2 Belgium \n", + "1182 Customer group 1 Product ID 9 Product group 2 Spain \n", + "1183 Customer group 1 Product ID 7 Product group 2 Spain \n", + "\n", + " bu_level_2 volume ... payment_term_discount off_invoice_discount \\\n", + "0 BU 1 46.943272 ... 7.759970 11.770865 \n", + "1 BU 2 0.244745 ... 0.062206 0.026333 \n", + "2 BU 1 59.513061 ... 12.493186 20.693476 \n", + "3 BU 2 75.271004 ... 21.871783 35.406659 \n", + "4 BU 2 49.097800 ... 24.137916 20.240287 \n", + "... ... ... ... ... ... \n", + "1179 BU 2 44.926780 ... 11.268036 10.816130 \n", + "1180 BU 2 44.919097 ... 11.266118 10.813684 \n", + "1181 BU 2 44.911413 ... 11.264201 10.811238 \n", + "1182 BU 2 44.903730 ... 11.262284 10.808792 \n", + "1183 BU 2 44.896047 ... 11.260366 10.806347 \n", + "\n", + " pocket_sale cogs other_cogs_adjustement gross_margin \\\n", + "0 867.803405 486.963591 21.330551 359.509264 \n", + "1 3.609343 2.516189 0.091420 1.001733 \n", + "2 762.302336 610.281152 7.668668 144.352516 \n", + "3 949.623457 782.845460 25.053287 141.724710 \n", + "4 647.291458 514.161774 1.755194 131.374490 \n", + "... ... ... ... ... \n", + "1179 671.707586 460.524320 10.921017 200.262248 \n", + "1180 671.602018 460.446474 10.918850 200.236695 \n", + "1181 671.496451 460.368628 10.916682 200.211141 \n", + "1182 671.390883 460.290781 10.914515 200.185587 \n", + "1183 671.285315 460.212935 10.912347 200.160033 \n", + "\n", + " net_sale_gross_margin freight_cost other_cost_to_serve net_margin \n", + "0 377.118089 13.333149 15.808454 347.976486 \n", + "1 1.006250 0.029201 0.121736 0.855313 \n", + "2 128.449528 9.567616 28.229236 90.652676 \n", + "3 142.235214 16.523587 5.266430 120.445198 \n", + "4 160.811160 18.057862 12.840612 129.912686 \n", + "... ... ... ... ... \n", + "1179 199.164794 12.852895 10.100944 176.210955 \n", + "1180 199.137410 12.852996 10.097111 176.187302 \n", + "1181 199.110026 12.853097 10.093278 176.163650 \n", + "1182 199.082642 12.853199 10.089446 176.139998 \n", + "1183 199.055258 12.853300 10.085613 176.116345 \n", + "\n", + "[1184 rows x 26 columns]\n" + ] + } + ], + "source": [ + "s3 = boto3.client('s3')\n", + "obj = s3.get_object(\n", + " Bucket='cortex-kedroservice-demo-bucket',\n", + " Key='cortex-churn/churn_pipe/data/demo/03_primary/dp_full_datacube_output_for_models.csv'\n", ")\n", "\n", - "Vizro(assets_folder=\"../assets\").build(dashboard).run()" + "df = pd.read_csv(obj['Body'])\n", + "\n", + "print(df)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "vizro", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "vizro" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -564,9 +244,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file