import sys, subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '--upgrade','epyk'])
0
A Pyk report is a report that allows you to specify objects to export for another reports to use. This is especially useful to prevent you to duplicate code that is fairly reusable. With this method you can reuse components that you're particularly proud of or even things you want to share for other people to leverage on !
To take advantage of this feature you simply need to declare within your reports the objects you would like to be reusable. This is very similar to the Node.js export/require mechanisms.
First - Within a report you've created you can define functions/epyk components you would like to share. For instance we've create a pyk_report.py script that looks like this:
from epyk.core.Page import Report
rptObj = Report()
button = rptObj.ui.buttons.button('This is button')
imp = rptObj.ui.buttons.important('This is an important button')
rptObj.outs.jupyter()
For now this script left like this wouldn't be able to share anything with another report. To remedy that you just need to add those lines:
from epyk.core.py import Pyk
Pyk.exports({'button': button, 'imp': imp})
Here we simple tell Epyk that we wish to exports
our button and imp components using a dictionary. The key of the dictionaries are simply the aliases we wish to give our object. These aliases will be used to then retreive the object on the consumer side.
from epyk.core.Page import Report
from epyk.core.py import Pyk
rptObj = Report()
button = rptObj.ui.buttons.button('This is button')
imp = rptObj.ui.buttons.important('This is an important button')
Pyk.exports({'button': button, 'imp': imp})
rptObj.outs.jupyter()
Here we have created our output for jupyter AND we specified that some of our components were going to be reused elsewhere. We could have very well skipped the rptObj.outs.jupyter()
. But we wanted to show that both method were not exclusive.
Now both button
and imp
would be available to be called from another report
Now to be able to use objects coming from a Pyk, we will see what needs to be done on the consumer side.
First we need to specify where we're going to need to pick up object. This is done through the requires
method:
from epyk.core.Page import Report
pyk_rpt = Pyk.requires(r'<path>pyk_report.py')
or
pyk_rpt = Pyk.requires('pyk_report') #if pyk report is on Pypi
The requires
method will work for two cases:
autoinstall
argument to True
Finally to add the imported object to your report you will need to call the register
function at the moment you want to add your component within the report.
rpt_obj.register(pyk_rpt.button)
This accept accept a single components as well as a list of those
import os
from epyk.core.py import Pyk
from epyk.core.Page import Report
pyk_rpt = Pyk.requires(os.path.abspath('pyk_report.py'))
rptObj = Report()
rptObj.ui.text("Here we have a text followed by a normal button")
rptObj.register(pyk_rpt.button)
rptObj.ui.text("Then we have an important button")
rptObj.register(pyk_rpt.imp)
rptObj.outs.jupyter()
You now have a mixture of object defined from your own report and object imported from another one !!