Skip to content

Add example pattern for pulling JsCode snippets from external javascript files #1942

@thomasegriffith

Description

@thomasegriffith

Is your feature request related to a problem? Please describe.
I have found myself embedding a lot of javascript code via JsCode when using the Realtime plugin. This gets messy for a few reasons:

  • unit testing the javascript code is not possible
  • adding leaflet plugins can result in a huge amount of javascript code embedded inside python
  • and the code is just not as modular as it could be

I'm wondering if there's a recommended way to solve this.

Describe the solution you'd like
A solution would allow one to reference specific functions from external javascript files within a JsCode object.

It's not clear to me what would be better: whether to do this from within folium (using the API) or to use some external library to populate the string of javascript code that's passed to JsCode based on some javascript file and function. In either case, having an example in the examples folder would be great.

Describe alternatives you've considered
If nothing is changed about the folium API, this could just be done external to folium. As in, another library interprets a javascript file, and given a function name, the function's definition is returned as a string. Is this preferable to building the functionality into folium? If so, does anybody know of an existing library that can already do this?

Additional context
n/a

Implementation
n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions