Plugin in with more than one macro component
![weaam7](https://us.v-cdn.net/6038231/uploads/Dataiku/nAvatar23.png)
Hello everyone,
I wonder if there is a way to have more than one macro within the same plugin,
in which one of them will be used as the base macro, and based on its result the user will be directed to the UI of another macro that matches the selected option, fill its form and run it.
I know it is possible to hide/show params based on selection, but I am trying to find a good way to modularize my steps/code.
Thank you!
Answers
-
Hi @weaam7
,There are a couple ways that you can make macro components more modular.
You can reuse Python code between multiple macros by defining shared code in the python-lib/PLUGIN_ID directory within the plugin. You can then import this directory into your macros.
See the below example. Be sure to replace PLUGIN_ID with the name of your actual dir.# python-lib/PLUGIN_ID/__init__.py def my_shared_function(): ... # Do stuff here # python-runnables/MACRO_NAME/runnable.py from PLUGIN_ID import my_shared_function class MyRunnable(Runnable): def run(self, progress_callback): my_shared_function()
You can reuse parameters between macros by defining a parameter set. See Preset parameters for documentation.If the above solutions don't fit your needs, you may want to consider creating a webapp. Webapps require more work to set up, but they are a lot more customizable. See Webapps for more information.
Please let me know if you have any questions.
Thanks,
Zach -
Hello @ZachM
,I might have not explained what I want well,
I want to create a root macro, which based on its selection, the user will be directed to a task-specific macro interface that will take the required inputs of what was selected then perform the task. Is it possible?
Thank you!
-
Hi @weaam7
,Sorry for the confusion. There's no way to direct a macro to another macro.
Instead, I recommend using a single macro that uses conditional parameters to show/hide inputs.
Alternatively, you can use multiple separate macros like I described in my last post.
If you want the GUI of the macro to be more customizable, you can also write a custom GUI in JavaScript/HTML. See Custom settings UI for more information.
If you want it to be even more customizable, there's also webapps like I described in my last post.
Thanks,
Zach