Select to view content in your preferred language

ArcGIS Python Export Map to HTML is blank

1205
11
04-19-2023 01:41 PM
UnsungHer0z
New Contributor II

Creating a map in Jupyter notebook allows me to display a map, but when I use the export_to_html() or embed() methods, the map is blank.

#gis defined above using api key
map1 = gis.map('California, USA', zoomlevel=5)
map1

 This code produces this:

UnsungHer0z_0-1681936741543.png

Using export_to_html(), the file is blank when opened in Firefox. When using embed, this is the result:

UnsungHer0z_1-1681936837101.png

 

 

11 Replies
NicolasRojas
New Contributor III

Have you tried the method `take_screenshot` inside the notebook?

-N
0 Kudos
JenniferSmits
New Contributor III

Same for me. Saves, but looks blank. I have tried screenshot and that was fine but is not what i want (I am using AGOL notebooks). Adapted from here: https://developers.arcgis.com/python/guide/part5-saving-updating-and-embedding-map-widget/

from arcgis.gis import GIS
gis = GIS("home")

aus_item = gis.content.get('b6e35d7687844967b8afe559275b7105') #this isnt public
aus_layer = aus_item.layers[0]
aus_layer

map1 = gis.map("AUS")
map1.add_layer(aus_layer)
map1

JenniferSmits_0-1697354485803.png

import os

file_dir = os.path.join(os.getcwd(), 'home')
if not os.path.isdir(file_dir):
os.mkdir(file_dir)
file_path = os.path.join(file_dir, 'Mapr.html')

map1.export_to_html(file_path)
TRUE

html saved as /arcgis/home/Mapr.html".... open that from files tab in Notebooks... opens blank. Cant seem to download. Help!


 

ErinKiley
New Contributor II

Could @JeffPace 's comment on this issue ( https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-api-js-tutorial-maps-showi... ) have something to do with it?

 

For the record---I'm having the same issue, and I don't have a website to host the HTML page on---I just want to show it to my boss as a one-off (to visualize the addresses in a .csv file she sent me). It would be nice to be able to do this somehow?

For my case, it doesn't have to be an HTML output---it could be any other format, but the addresses are clustered in areas of a map that are far from each other (think: across a continent), so the 'screenshot' method won't work very well for my purpose.

0 Kudos
ErinKiley
New Contributor II

However... the instructions here ( https://developers.arcgis.com/python/guide/advanced-map-widget-usage/ ) under the heading "Export to HTML" clearly state "The below cell will write the current widget to the file specified by a string path. Run the cell, find the file on your disk, and open it in your favorite web browser."

It seems to me that needing to have the HTML file hosted somewhere in order to view it would contradict the documentation, which suggests the HTML file can be opened locally?

Maybe I am misunderstanding.

0 Kudos
UnsungHer0z
New Contributor II

That comment was from 2014 and for the JavaScript version, this is related to Python and the 1.5.0 version which has this export to html method was released in 2018, so I don't think it has anything to do with it. I am not seeing any requirements stating this has to be hosted somewhere. The only caveat the method has is this: "Note: By default, only publically accesible layers will show on the exported HTML maps. You must specify credentials_prompt=True to allow users to authenticate to portal to view private layers. See the API reference for more information."  I do not believe I am using any private layers, as I am just following the tutorial mentioned by Jennifer. I am at a loss here.

0 Kudos
ErinKiley
New Contributor II

I'm following the same tutorial you are, using a Jupyter notebook with the Python API, and getting the same issue you are: an HTML file that shows up as a blank webpage when I try to view it in a web browser by opening the file locally.

This is the code I'm using as a minimal working example:

 

from arcgis.gis import GIS
gis = GIS()
map2 = gis.map()
map2.export_to_html('test_map.html')

 

The resulting HTML file cannot be attached in a comment on this forum, but you can see it here: ( http://erinkiley.com/test_map.html ) and can read what's in it by choosing "view source", however your particular browser lets you do that. Point is, the file's not blank (far from it: it contains some 13k lines).

The comment I linked from 2014 in the Javascript API forum is related to the same issue: a user exported a map to an HTML file (using the Javascript API---yes, it's different from the Python API, but hear me out), and the exported HTML file showed up as a blank webpage when the user tried to view it in a web browser by opening the file locally. The comment on that post reads, in its entirety, "just to be clear. You HAVE to run the file on a server. You cannot run it locally (file://)".

I am really not a web developer, just looking to generate a map I can share with my boss. I don't know if there's such a thing as an HTML file that cannot be viewed when it is "run locally", but that can be viewed when it is "run on a server". But it seems like the behavior I'm seeing---both from the example I've tried, from the example you've tried, and from the example on the Javascript API forum (especially with that comment, cryptic as I think it seems)---is consistent with that hypothesis.

I'm not really clear on what it means to "run the file on a server"? But I have a personal website and I placed this file on the server that provides web hosting (and changed its permissions to 755). When I try to load this file by opening my web browser (for good measure, I've tried Opera, Firefox, and Edge) and navigating to the publicly viewable URL I saved the file under, it still shows a blank page with the title "Exported ArcGIS Map Widget", just like it does when I "run it locally".

Sorry, but I'm still at a complete loss as to why this is happening with the simplest test example. Here's hoping someone with more wisdom can chime in and drop a lead for us to follow.

0 Kudos
ErinKiley
New Contributor II

Also---there's another comment on that Javascript post that reads


What is the URL you are trying to view in your web browser to see your local .html file? If it's something along the lines of 'C:\web\test.html', then you'll probably want to try and put that file in your 'C:\inetpub\wwwroot' directory (you should have this directory if you have IIS installed on your machine), and then view the file using localhost.

This comment is actually much clearer now than I thought it was when I first read it. It does seem to be the case that local files and files served from web servers are treated differently by web browsers: see the top Answer here ( https://stackoverflow.com/questions/40204913/difference-between-localhost-and-opening-html-file ).

So, I'm going to follow the tutorial here ( https://katiekodes.com/python-http-server-windows/ ) and see if it helps clarify what I need to do with the HTML file that the ArcGIS Python API generates.

0 Kudos
maya_fromstein
New Contributor III

hi! currently having the same issue where my html file is blank. did you find a solution? did that tutorial help? thanks !

0 Kudos
UnsungHer0z
New Contributor II

I have not found a solution to the issue described. I HAVE found a workaround solution using the folium package. Basically I wanted to plot points and routes on an interactive HTML map, so I used the ARCGIS packages to geocode my addresses and used that address/routing data to plot on a folium generated map.

0 Kudos