plotly / plotly/plotly.py

allow custom HTTP headers (e.g. bearer token) to Mapbox layer source

Open
#4,566 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

Hi!

I wanted to display a Mapbox layer that requires authentication through bearer tokens, i.e. when doing something like:

fig.update_layout(
    mapbox_style="white-bg",
    mapbox_layers=[
        {
            "below": 'traces',
            "sourcetype": "raster",
            "sourceattribution": "My private ortho",
            "source": [
                "https://my_private_source.com/MapServer/tile/{z}/{y}/{x}"
            ]
        }
      ]
)

I need to pass custom HTTP headers to each tile request. In JavaScript, this can be easily achieved with the Mapbox API thanks to transformRequest (see here):

const map = new mapboxgl.Map({
  container: 'map',
  center: [2.35, 48.86],
  zoom: 13,
  transformRequest: (url, resourceType) => {
    if (url.startsWith('https://my_private_source.com')) {
      return {
        url: url,
        headers: { 'Authorization': 'Bearer ' + my_private_token }
      }
    }
  }
});

However, this does not seem supported by plotly.py, or am I missing something? With some pointers I could work on a PR, but I'm not sure where to start in the code base.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by tracing how plotly.py serializes mapbox_layers and how the JavaScript map requests raster tiles, then compare that path with the linked transformRequest example. Done means custom headers can be supplied for each Mapbox layer tile request and the behavior is covered by appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.