I am playing around with Arcgis, a mapping tool.
It has an api in python which I have downloaded and gotten to work properly (it imports and runs properly).
My problem is that the map is not being rendered within my IDE (VSCode, PyCharm or DataSpell). When I open the notebook inside of my browser, the map shows up properly and it can be interacted with etc. I believe the map itself is made using html but the IDE's im using are unable to display the maps. Is there a setting or a package I can download to show the map?
Expected Behavior:
This code:
from arcgis.gis import GIS
gis = GIS()
m = gis.map("Berlin")
display(m)
should display this.
Rather it displays this.
How would I get the HTML/Map render to be displayed inside of my IDE?
Related
I am attempting to generate a plot in Jupyter Lab's notebook and encountering an odd issue. For the plot I wanted to change the shape of the node using an image. When the notebook runs it generates the plot but does not render the image. However the resulting HTML file, when loaded in a webbrowser renders the image fine.
import os
import pyvis
import networkx as nx
from pyvis.network import Network
os.chdir('/my/path/to/my/JupyterWork') #as suggested in SO 65131541
graph = Network(height=800, width=800,notebook=True,directed=False)
graph.add_node("NodeName",shape="image",image='path/to/image.png',label="NodeName")
graph.add_node("NodeName2",shape="image",image='path/to/image2.png',label="NodeName2")
graph.show('test.html')
The result is that in the notebook the edge will connect two blank spaces (ie I dont get a broken image icon). Whereas if I load the output file, test.html, in a browser I will instead see image.png being connected to image2.png
I tried using an HTTP source,
http://localhost:8888/path/to/image.png
but it similarly does not load in the notebook, but does load in the HTML file in a browser. Oddly enough I can view the image in the Jupyter Lab console
For reference the Jupyter Lab version was 3.1.11
Any help,ideas, or feedback is welcome.
Ok I believe this is solved. Based on the responses from a thread in GitHub: https://github.com/altair-viz/altair/issues/2318 ,I took the idea of identifying the image by it's base64 encoded address.
Except it was somewhat different from the solution in GH. Instead I used the copy downloadable link that Jupyter provides for the image, which is the same as the shareable link except it contains an _xsrf value appended to the end of the link.
Including this the downloadable link allows the image to be rendered in the Jupyter notebook.
I am new to programming, so forgive the question if it seems simple.
I have been using Python and its libraries to make plots. I am attempting to import an interactive graph I plotted using the plotly graphing library and display it in the Jupyter notebook.
The graph is saved as an html file. I need the graph to remain as an html file to retain the graph's features and interactivity (zooming in/out, changing the scales, hiding certain data, etc).
So far, I have written out this bit of code:
import plotly
import os
os.chdir(r'C:\Users\alsha\Documents\CE-CERT - SIGI\CMC Data')
from IPython.display import HTML
HTML(filename="./CopperMountainCollegeEntireInterval.html")
I do not know what code to write to display the actual graph, I would appreciate any help I receive.
I am probably a year to late, but the easiest way would be to import IFrame from IPython.display and use it like
from IPython.display import IFrame
IFrame(src='path_to_html', width=500, height=500)
To complete Luca R answer (his solution works fine): In my case though, I noticed that to use IFrame, I needed to place the html file in the same directory as my notebook (or in a subdirectory under the notebook) and then use a relative path. It is probably due to common browser security settings (see more from https://community.plotly.com/t/displaying-html-file-generated-by-plotly-offline-in-a-jupyter-notebook/19586)
I’m building a GUI (pyqt or pyside) to easily create complex figures (e.g. with plotly) for users.
So far so good, I run the data processing and produce plotly figures that are exported as html and read by QwebEngineView. I even created a qt widget for layout editing by the user (see image below).
The problem with this is the long delay (few seconds) in the process of:
updating the layout -> exporting to a temp html file → open and rendering the file on GUI.
I want to make a better GUI experience with layout editing.
Following this great Jon Mease talk I discovered my plotly figures could be updated in real time using the also great ipywidgets, but only on Jupyter notebooks / lab environment. That is, exporting the widgets+figure to a html file renders all elements, but since the python backend will be lacking for the widgets (in the standalone html file), they won’t interact with the figure’s layout.
However, my application IS running on a python process, so I have the feeling this should be a solvable problem somehow...
Qtconsole won’t render ipywidgets, so I can’t use it to expose my figures in the GUI.
Voila renders Jupyter notebooks with interactive widgets, I’m not sure however if I could access it and incorporate it to the GUI. It says it can work both as a “standalone tornado application” or as a “server extension to notebook or jupyter_server”.
I’m aware there’s probably not a final solution to that, but I would appreciate any suggestions on how to approach this problem! Thanks!
I ended up creating a solution for the problem: QtVoila
It is basically an extended QWebEngineView that manages and renders a Voila process, with some extra functionalities.
Here's a blog post explaining it:
https://www.taufferconsulting.com/portfolio/qtvoila
In my notebook, I can display image in markdown from the same folder like this:
<img src="files/adaptive_filter.png" alt="Schema of adaptive filter" height="100">
If I use the code without the files/ in src it does not work.
Now I changed the image and the ipython notebook is still showing the original one. I try to remove it from code and restart the notebook, it does not help.
What I should do? Are the images stored somewhere?
Thanks in advance.
I ran into this problem as well, where I was using a class of my own to output some python plots and embed them in an IPython notebook. A hack way to solve this would be to add a random argument to the end of your image url. For example
<img src="files/adaptive_filter.png?1" alt="Schema of adaptive filter" height="100">
will not be cached in the same place as
<img src="files/adaptive_filter.png?2" alt="Schema of adaptive filter" height="100">
A programatic way to do this would be to include the picture via python, instead of markdown, for instance:
# pick a random integer with 1 in 2 billion chance of getting the same
# integer twice
import random
__counter__ = random.randint(0,2e9)
# now use IPython's rich display to display the html image with the
# new argument
from IPython.display import HTML, display
display(HTML('<img src="files/adaptive_filter.png?%d" ' +
'alt="Schema of adaptive filter" ' +
'height="100">' % __counter__))
Should update the image everytime you run the code cell
I ran into exactly the same problem. The following procedure works for me:
In the folder where your .ipynb file resides, there is a cache directory called .ipynb_checkpoints/. There should be a file in that cache directory that has the same file name as the one you are working on. Now remove/delete that cache file in the .ipynb_checkpoint/ directory then reload the browser. You should be able to see the updated image.
My environment: macOS 10.14.2, Chrome browser 71.0, and Jupyter 1.0.0 installed through anaconda.
Hope this helps.
I had the same problem of images caching in jupyter and not updating when the file is modified when using matplotlib.pyplot. I fixed it by using IPython.display.Image
from IPython.display import Image
def saveImage(path, show=True):
plt.savefig(path, facecolor="white", bbox_inches='tight')
if show: return Image(path)
Then at the end of a code cell, something like saveImage('./someImage.png') will save and display an image.
Similarly Image('./someImage.png') will display an image from disk (without saving).
This seems to avoid caching issues, and the image displays in PDF exports correctly (see also Jupyter notebook matplotlib figures missing in exported pdf for the answer this is based on).
In my case, it helped reduce the size of the jupyter notebook, preventing it from crashing when rendering and updating matplotlib.pyplot charts.
In ipynb file directory,use ls command ,it will display a hidden
directory .ipynb_checkpoints
Delete the .ipynb_checkpoints directory ,then rerun the cell
code,you will see the newest image.
When using the web based iPython Notebook/Jupyter capability, i created a notebook with markdown cells of text and code cells to display the code and plots for matplotlib and bokeh. I then download that as .ipynb open with sublime, copy and paste to git, then access it on nbviewer through my git account. When looking at it here:
http://nbviewer.ipython.org/github/angisgrate/test/blob/master/pyohio3.ipynb
in notebook view, it works fine. the markdown, code, and plot steps are all there.
When switching to slides view, the intent of the creation needed for the presentation, this code blocks occurs first, blocking out the first 10 markdown steps and all the matplotlib steps, rendering this weird code without the plots:
http://nbviewer.ipython.org/format/slides/github/angisgrate/test/blob/master/pyohio3.ipynb
How can i fix this asap?? I've looked through and there was a similar problem in 2014 with slides, but it yielded an actual "Error" that i'm not seeing, just this contorted view
I can't say for certain. It's possible in the nbviewer slides view, the execution of JavaScript is suppressed (this happens on GitHub notebook previews, for instance). All of the rendering in Bokeh actually happens from the JavaScript library BokehJS, so if this is the case, then Bokeh will not function, and there is nothing really that can be done. This is probably a question bset directed towards the nbviewer team/community to find out the specifics of how the slides view behaves (and is intended to behave) with respect to executing embedded JavaScript.
Edit: Looks like this is a known/discussed issue. More information here: Issue #484: Jupyter>>nbviewer slides Fail, notebook view fine by angisgrate in jupyter/nbviewer on GitHub