Metadata

Distro Index Owner:
eea
Home Page:
eea.jupyter
License
GPL version 2
Version:
1.2
Last updated:
2025-01-16
Keywords:
EEA Utilities

eea.jupyter

Files

Indexes

eea.jupyter utilities for jupyter notebook

eea.jupyter

Develop Master

The eea.jupyter is a jupyter utility package for EEA.

Installation

System Message: WARNING/2 (<string>, line 18)

Cannot analyze code. Pygments package not found.

.. code-block:: console

  pip install eea.jupyter


Usage

System Message: WARNING/2 (<string>, line 26)

Cannot analyze code. Pygments package not found.

.. code-block:: python

  from eea.jupyter import upload_plotly

Uploads or creates a Chart (interactive) to a specified url. This function accepts any number of keyword arguments.

Parameters:

  • url (required): The URL of the visualization to be updated or created, e.g. https://eea.europa.eu/en/sandbox/chart-1. Default: None
  • fig (required): The figure to be used as part of the visualization. Can accept a plotly.graph_objs.Figure or a dict. Default: None
  • api_url (optional): The base URL of the plone API, e.g., https://eea.europa.eu/admin/++api++. Default: /++api++ concatenated to the hostname of the visualization URL, e.g.: if the url is https://biodiversity.eea.europa.eu/en/sandbox/chart-1 then the default value for api_url will be https://biodiversity.eea.europa.eu/admin/++api++
  • auth_provider (optional): Provider to be used for authentication. Allowed values: basic, microsoft. Default: basic
  • auth_token (optional): Token to be used instead of allways authenticating. Default: None
  • __ac__key (optional): Key to be used in cookies if microsoft auth_provider is used. Default: __ac
  • **metadata (optional): Any Chart (interactive) metadata desired to be customized, e.g., title, description, topics

Example 1: how to use it with basic authentication

System Message: WARNING/2 (<string>, line 44)

Cannot analyze code. Pygments package not found.

.. code-block:: python

  # Cell 1 will have some logic to generate a fig
  # Cell 2
  from eea.jupyter import upload_plotly

  url = "https://www.eea.europa.eu/en/sandbox/miu-test/chart-1"

  metadata = {
    "title": "Chart 1 example",
    "description": "This exemplifies how to use upload_plotly"
  }

  upload_plotly(url=url, fig=fig, **metadata)

In this example you specify the visualization that you want to update, if it already exists, or where you want to create it. In case the visualization doesn't exists it will be created inside of https://www.eea.europa.eu/en/sandbox/miu-test with the id of chart-1. After calling upload_plotly you will be prompted with username and password inputs.

Example 2: how to use it with microsoft authentication

System Message: WARNING/2 (<string>, line 64)

Cannot analyze code. Pygments package not found.

.. code-block:: python

  # Cell 1 will have some logic to generate a fig
  # Cell 2
  from eea.jupyter import upload_plotly

  url = "https://www.eea.europa.eu/en/sandbox/miu-test/chart-1"

  metadata = {
    "title": "Chart 1 example",
    "description": "This exemplifies how to use upload_plotly"
  }

  upload_plotly(url=url, fig=fig, auth_provider="microsoft", __ac__key="__ac__eea", **metadata)

In this example you specify the microsoft auth_provider and also the key of __ac.

After calling upload_plotly you will be prompted with auth_token input which expects a valid __ac token. To get the __ac you will need to authenticate on https://www.eea.europa.eu/admin and get the value of __ac__eea cookie. You can use a cookie chrome extension to retrive the value of the cookie.

Example 3: initialize auth_token so that you can pass the authentication input

System Message: WARNING/2 (<string>, line 85)

Cannot analyze code. Pygments package not found.

.. code-block:: python

  # Cell 1 will have some logic to generate a fig
  # Cell 2
  auth_token = input()
  # Cell 3
  from eea.jupyter import upload_plotly

  url = "https://www.eea.europa.eu/en/sandbox/miu-test/chart-1"

  metadata = {
    "title": "Chart 1 example",
    "description": "This exemplifies how to use upload_plotly"
  }

  upload_plotly(url=url, fig=fig, auth_provider="microsoft", __ac__key="__ac__eea", auth_token=auth_token, **metadata)

In this example, firstly, you will be prompted with specifying the value of auth_token, which will then be added as a parameter to upload_plotly. This allows you to initialize the value of auth_token only once, then you can run cell 3 as many times as you like.

Same behaviour regardless of the auth_provider.

Example 4: passing multiple types of metadata

System Message: WARNING/2 (<string>, line 108)

Cannot analyze code. Pygments package not found.

.. code-block:: python

  # Cell 1 will have some logic to generate a fig
  # Cell 2
  auth_token = input()
  # Cell 3
  from eea.jupyter import upload_plotly

  url = "https://www.eea.europa.eu/en/sandbox/miu-test/chart-1"

  metadata = {
    "title": "Chart 1 example",
    "description": "This exemplifies how to use upload_plotly",
    "topics": ["Agriculture and food"],
    "temporal_coverage": [2011, 2020],
    "geo_coverage": ["Italy"],
    "subjects": ["tag 1"],
    "data_provenance": [
        {"title": "European Environment Agency", "organisation": "EEA", "link": "https://eea.europa.eu"}
    ]
  }

  upload_plotly(url=url, fig=fig, auth_provider="microsoft", __ac__key="__ac__eea", auth_token=auth_token, **metadata)

Metadata

In this section you will learn about various metadata that can be specified when calling upload_plotly.

  • figure_note (slate): sets the figure note
  • topics (list): sets the list of strings for topics (e.g., ["Agriculture and food", "Bathing water quality"])
  • temporal_coverage (list): sets the list of years for temporal coverage (e.g., [2022, 2023, 2024])
  • geo_coverage (list): sets the list of strings for geographical coverage (e.g., ["Italy", "Romania"])
  • subjects (list): sets the list of strings for tags (e.g., ["tag 1", "tag 2"])
  • data_provenance (list) sets the list of data provenance (e.g., [{ "title": "European Environment Agency", "organization": "EEA", "link": "https://eea.europa.eu"}])

If any of these doesn't meet the required format, you will get an error explaining what is wrong.

If, for example, you specify topics = ["Agriculture and fod"] with a typo, you will get an error because the topic is not in the topics vocabulary and a list with the available topics will be printed.

Funding

EEA - European Environment Agency (EU)

Changelog

1.2 - (2025-01-16)

  • Change: Add preview_image [razvanMiu]

1.1 - (2025-01-16)

  • Change: Add new function, uplod_plotly, to automate jupyter workflow [razvanMiu]

1.0 - (2024-12-04)

  • Change: make uploadPlotly accept dict, ref #281230 [razvanMiu]

0.9 - (2024-02-02)

  • Change: update readme + set postMessage origin [razvanMiu]

0.8 - (2024-02-01)

  • Change: fix import [razvanMiu]

0.7 - (2024-02-01)

  • Change: add uploadPlotly function wrapper [razvanMiu]

0.6 - (2024-01-30)

  • Change: Develop [razvanMiu]

0.5 - (2024-01-30)

  • Change: Develop [razvanMiu]

0.4 - (2024-01-30)

  • Change: Develop [razvanMiu]

0.3 - (2024-01-30)

  • Change: Develop [razvanMiu]

0.2 - (2024-01-30)

  • Change: 0.2 [razvanMiu]

0.1 - (2024-01-19)

  • Initial release. [eea]