Repository: projectmesa/mesa

Issue:
Advanced tutorial chart
I have been unable to get the chart showing the gini coefficient to open up in  the advanced tutorial to open up. Everything else is working, the chart just does not appear. Please advise, 

Thank you.

Tom 


Discussion:
Please make your code publicly available and provide a link.

On Thu, Nov 10, 2016 at 1:07 PM, tpike3 notifications@github.com wrote:

> I have been unable to get the chart showing the gini coefficient to open
> up in the advanced tutorial to open up. Everything else is working, the
> chart just does not appear. Please advise,
> 
> Thank you.
> 
> Tom
> 
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> https://github.com/projectmesa/mesa/issues/337, or mute the thread
> https://github.com/notifications/unsubscribe-auth/AAKLTgDcFGO1lSKo3kygrLDBU3n7hFV9ks5q811kgaJpZM4Ku9u1
> .

## 

Jacqueline Kazil | @jackiekazil

`
Sorry about, attached is the code in PDF. 

[advanced tutorial code.pdf](https://github.com/projectmesa/mesa/files/584711/advanced.tutorial.code.pdf)

`

Was this generated with ipython or jupyter notebook? (if so, can you share
that?)
And do you have any errors that you are getting? can you share those as
well?

On Thu, Nov 10, 2016 at 6:56 PM, tpike3 notifications@github.com wrote:

> `
> Sorry about, attached is the code in PDF.
> 
> advanced tutorial code.pdf
> https://github.com/projectmesa/mesa/files/584711/advanced.tutorial.code.pdf
> 
> `
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> https://github.com/projectmesa/mesa/issues/337#issuecomment-259843332,
> or mute the thread
> https://github.com/notifications/unsubscribe-auth/AAKLTkGB0NGfMUgWBSKYxJPU99MO-CL1ks5q868VgaJpZM4Ku9u1
> .

## 

Jacqueline Kazil | @jackiekazil

Sorry for the delay I had to learn how to load the file on gist; 

Link below. 

https://gist.github.com/tpike3/bcb34adc9de2f4247d7354bf902e7872  

I tried it and that should give you everything you need. Thank you. 

It looks like this is an interaction between the jupyter notebook and the visualization server. The server launches and works, but it leaves these errors in the notebook. I'll look into a fix.


Resolving patch:
diff --git a/mesa/visualization/ModularVisualization.py b/mesa/visualization/ModularVisualization.py
--- a/mesa/visualization/ModularVisualization.py
+++ b/mesa/visualization/ModularVisualization.py
@@ -80,6 +80,7 @@
 """
 import os
 
+import tornado.autoreload
 import tornado.ioloop
 import tornado.web
 import tornado.websocket
@@ -209,6 +210,7 @@ class ModularServer(tornado.web.Application):
     handlers = [page_handler, socket_handler, static_handler, local_handler]
 
     settings = {"debug": True,
+                "autoreload": False,
                 "template_path": os.path.dirname(__file__) + "/templates"}
 
     def __init__(self, model_cls, visualization_elements, name="Mesa Model",
@@ -254,10 +256,13 @@ def render_model(self):
 
     def launch(self, port=None):
         """ Run the app. """
+        startLoop = not tornado.ioloop.IOLoop.initialized()
         if port is not None:
             self.port = port
         url = 'http://127.0.0.1:{PORT}'.format(PORT=self.port)
         print('Interface starting at {url}'.format(url=url))
         self.listen(self.port)
         webbrowser.open(url)
-        tornado.ioloop.IOLoop.instance().start()
+        tornado.autoreload.start()
+        if startLoop:
+            tornado.ioloop.IOLoop.instance().start()


Test patch: