Interaction with xoe
Create a chart, install python package and set the options.
The xplain session instance shall be created by the constructor method
xplain.Xsession(),
the constructor shall be called without parameters likeurl, username and password
xplain.startup() or xplain.load_from_session_id() are not necessary, the xplain session is take over from the current XOE xplain session.
Any xplain session changes made by python code will automatically reflected in XOE, and vice versa.
In Web Assembly environment, the options values can be accessed inside python code via the global dict
args
. For example you have defined following options: –gender=”male”, to access this option in python code you could useargs.get("gender")
Example code for interaction with xoe:
import xplain
print(f'args: {args}')
GenderSelection = args.get('Gender')
methodCalls = [
{
"method": "setPropagateSelectionsUpward",
"propagateSelectionsUpward": False
},
{
"selectionSet": "globalSelections",
"selections": [
{
"attribute": {
"name": "Gender",
"attribute": "Gender",
"dimension": "Gender",
"object": "Patients"
},
"selectedStates": [
GenderSelection
]
}
],
"method": "select"
},
{
"request": {
"requestName": "openGender",
"groupBys": [
{
"groupByName": "GROUP BY Gender",
"groupByLevelNumber": 1,
"groupByStatesFormHierarchyWithRoot": "Gender",
"includeUpperLevels": True,
"attribute": {
"name": "Gender",
"attribute": "Gender",
"dimension": "Gender",
"object": "Patients"
}
}
],
"requestId": "openGender",
"externalSelections": "globalSelections",
"aggregations": [
{
"aggregationType": "COUNT",
"aggregationName": "# Patients",
"complementMissingBranches": False,
"type": "COUNT",
"object": "Patients"
}
]
},
"method": "openQuery"
}
]
x = xplain.Xsession()
x.run({ "method": "executeBatch", "methodCalls": methodCalls})
Click on the menu.
Click on the “Python” button and then Click on “Start Python”
Click “New” and copy the above code example to the code block.
Enter packages that you want to install in pip install, for example: “xplain” and enter “–Gender=F” to set the gender as F.
Save the file as “InteractionXOE”.
Click “Run” to run the python script and you will see a newly created chart in xoe.