I have some custom python functions I have defined in QGIS which I use in print composer. I tried copying the python folder into the QGIS Server path but they do not get propagated. I have seen the following http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-Custom-python-expressions-in-QGIS-Server-td5362875.html but the answer seems vague to me. Any hints / documentation or that I could read on this anyone out there with an example that I could look at.
It depends how you have installed QGIS Server, you didn't mention it in your ticket.
If you are using Py-QGIS-Server for instance, it might be easier because it's a QGIS Server implementation in Python. I haven't tried. https://github.com/3liz/py-qgis-server
I am assuming you are not using Py-QGIS-Server, I have tried quickly by writing a quick QGIS Server plugin and it worked, so it is still easy. I have followed the link you gave more or less.
Make a folder called
In this folder, add a quick
[general] name=Server expression description=Expose Python expressions on QGIS Server about=Expose Python expressions on QGIS Server version=1.0 qgisMinimumVersion=3.4 author=Etienne Trimaille email@example.com server=True
In this folder, add a
from qgis.core import QgsMessageLog, Qgis, QgsExpression from qgis.utils import qgsfunction @qgsfunction( args='auto', group='Your group', usesGeometry=False, referencedColumns=, helpText='Define the help string here') def your_expression(params, feature, parent): # UPDATE the qgsfunction above # ADD HERE THE EXPRESSION CODE THAT YOU WROTE IN QGIS. return params.upper() class ServerExpressionPlugin: def __init__(self): QgsMessageLog.logMessage('Loading expressions', 'ServerExpression', Qgis.Info) QgsExpression.registerFunction(your_expression) def serverClassFactory(serverIface): _ = serverIface return ServerExpressionPlugin()
If in your layout, you have a label with
You will have a PDF with
To make things easy, I have added all the code in the
__init__.py. Of course, you can make your Python files listing your expressions, to make it easier to copy paste between Desktop and Server.