question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add custom html and JS to output html page

See original GitHub issue

Is there a way to add custom HTML and JS to the output page? Something like following would be nice, for example

my_before = '<script> abc ... </script>'  
my_after = '<p> Arctic Ocean</p>'
create_map('abc.html', plugin_data=True, before=my_before, after=my_after)

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:19 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
claudiodsfcommented, Mar 16, 2018

Hi, it looks like m.create_map() does not exist anymore.

Is there another way of using a custom template?

4reactions
FabeGcommented, Feb 28, 2019

Maybe would it be interesting to add a add_custom_js method to Map, that could allow to write direcly some parts directly in JavaScript in case the functionnality is not available in folium yet ?

For example, something in the class Map like:

def add_custom_js(self, custom_js):
    macro = MacroElement()
    macro._template = (Template("""{% macro script(this, kwargs) %}"""
                                + custom_js
                                + """{% endmacro %}"""))
    self.get_root().add_child(macro)

It would then be possible to plug some callbacks in folium, for example:

import folium

m = folium.Map()

customjs = """
{{kwargs['map']}}.on('click', function(e) {
    alert(e.latlng);
});"""

m.add_custom_js(customjs)
m.save('customjs.html', map=m.get_name())

Please let me know if this approach seems interesting (and deserves a PR) or if there are other simpler ways to do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Add JavaScript to HTML | DigitalOcean
This tutorial will go over how to incorporate JavaScript into your web files, both inline into an HTML document and as a separate...
Read more >
Adding HTML, CSS, and Javascript to a Page | Bandzoogle Help
How to add HTML, CSS or Javascript to a single page: ... Click 'Customize CSS'; Read the Bandzoogle custom CSS guidelines, click 'Ok, ......
Read more >
Adding custom HTML or Javascript to a web page
The most common way to insert HTML into a web page is by using the HTML object. You can use this to add...
Read more >
Inserting HTML into a div - javascript - Stack Overflow
I am trying to insert a chunk of HTML into a div. I want to see if plain JavaScript way is faster than...
Read more >
2 Ways to Add Custom HTML, CSS & JS to WordPress Page
One of those two methods requires a plugin and the other does not require a plugin. If you want to use them without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found