Calysto / calysto

Tools for Jupyter and Python
BSD 2-Clause "Simplified" License
20 stars 6 forks source link

No bar graph #9

Closed spalkovits closed 7 years ago

spalkovits commented 7 years ago

Hello, I am trying to get the Activity magic running from

https://athena.brynmawr.edu/jupyter/hub/dblank/public/Activity%20Magic.ipynb

I used a bank docker container with Jupyterhub. Everything works fine, I create a poll, get the answers, just the results graph is not showing (calysto is installed).

Any ideas?

Regards...

dsblank commented 7 years ago

Do you see a "Results" button? Do you see any errors in the JupyterHub console, where you started jupyterhub?

spalkovits commented 7 years ago

Hello,

I have a results button and it gives me an out put like

Received: Results ['1', '2'] [1, 0]

and I have nothing in the logs of the JupyterHub. Is calysto only important for the graphs? Then I could just take the results file and use e.g. pandas for the graphics.

Regards...

dsblank commented 7 years ago

That "Received:" line only prints out, I think, when there is an error (such as no data). But it is printing out data. Looks like an error in making the Bar graph. Calysto is only used for the SVG graphics and the barchart. You could use something else. Please let us know if you come up with a different graphics.

spalkovits commented 7 years ago

Well, of course directly getting the graph from the activity would be more convenient. If you have any additional feedback it would be nice. Are there e.g. any dependencies that I left out out when I used a fresh JupyterHub Docker container?

dsblank commented 7 years ago

Looking at the setup.py of calysto, I see that it requires 'svgwrite', and 'cairosvg'. Do you have those? Maybe we need to list those in a requirements.txt?

dsblank commented 7 years ago

Another test: does this work:

import calysto
b = calysto.graphics.BarChart((400, 200), data=[5, 4, 7])
b
spalkovits commented 7 years ago

'svgwrite' and 'cairosvg' seem to be installed but the test above leads to:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-7188dc9206f2> in <module>()
      1 import calysto
----> 2 b = calysto.graphics.BarChart((400, 200), data=[5, 4, 7])
      3 b

AttributeError: module 'calysto' has no attribute 'graphics'
dsblank commented 7 years ago

Perhaps calysto needs to update pypi. I'll take a look.

dsblank commented 7 years ago

What about this:

from calysto.graphics import BarChart
b = BarChart((400, 200), data=[5, 4, 7])
b
spalkovits commented 7 years ago

This leads to:


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-1-93e5a49bcc69> in <module>()
----> 1 from calysto.graphics import BarChart
      2 b = BarChart((400, 200), data=[5, 4, 7])
      3 b

/opt/conda/lib/python3.5/site-packages/calysto/graphics.py in <module>()
     22 import svgwrite
     23 from svgwrite import cm, em, ex, mm, pc, pt, px
---> 24 import cairosvg
     25 import numpy
     26 import math

/opt/conda/lib/python3.5/site-packages/cairosvg/__init__.py in <module>()
     27 import argparse
     28 
---> 29 from . import surface
     30 
     31 

/opt/conda/lib/python3.5/site-packages/cairosvg/surface.py in <module>()
     22 import io
     23 
---> 24 import cairocffi as cairo
     25 
     26 from .colors import color

/opt/conda/lib/python3.5/site-packages/cairocffi/__init__.py in <module>()
     39 
     40 
---> 41 cairo = dlopen(ffi, 'cairo', 'cairo-2')
     42 
     43 

/opt/conda/lib/python3.5/site-packages/cairocffi/__init__.py in dlopen(ffi, *names)
     36             except OSError:
     37                 pass
---> 38     raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
     39 
     40 

OSError: dlopen() failed to load a library: cairo / cairo-2
´´´
dsblank commented 7 years ago

Looks like a dependency on "libcairo2". On my Ubuntu, you would need "sudo apt install libcairo2".

spalkovits commented 7 years ago

It works now. The original poll now gives me a bar graph instead of writing just

Received: Results
['1', '2']
[1, 0]

Test number two which was

from calysto.graphics import BarChart
b = BarChart((400, 200), data=[5, 4, 7])
b

now also leads to a bar graph. But test number one which was

import calysto
b = calysto.graphics.BarChart((400, 200), data=[5, 4, 7])
b

still leads two

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-7188dc9206f2> in <module>()
      1 import calysto
----> 2 b = calysto.graphics.BarChart((400, 200), data=[5, 4, 7])
      3 b

AttributeError: module 'calysto' has no attribute 'graphics'

I modified the import statement to

import calysto.graphics as cg
b = cg.BarChart((400, 200), data=[5, 4, 7])
b

and now everything looks great. I would suggest to document the dependency somewhere.

Many thanks.

dsblank commented 7 years ago

Thanks for the feedback; glad it is working!

Updated the README.