PBR Posted August 19 Share Posted August 19 (edited) Hello, I had an earlier post regarding writing a IronPython script to show the corresponding line chart of a feature layer shape when it is triggered. https://community.spotfire.com/forums/topic/18365-how-to-make-a-connection-between-mapchart-feature-layer-and-line-chart/#comment-53097 Currently I am using a button to run the Ironpython script after the shape is selected. Is there a solution to automatically trigger the script whenever the shape is selected or changes? Edited August 19 by PBR Link to comment Share on other sites More sharing options...
Niko Maresco Posted August 19 Share Posted August 19 hi PBR the simplest way to achieve this is with a Data Function linked to a Document Property. first, create a Document Property of type String -- i'll refer to it as "ScriptTrigger". configure ScriptTrigger to execute your IronPython script when its value changes. next, create a Data Function that uses R script with the below code. on the Output tab, create an output parameter named "output" (to match the `output` variable in the script). output <- Sys.time() finally, go to the "Edit Parameters" dialog for the Data Function and on the Output tab, wire the output of the script to ScriptTrigger. make sure "Refresh Automatically" is ticked and save your changes. now when you open the analysis, the Data Function will be executed, which will produce a new unique value, which will update the Document Property, which will trigger your script :) Link to comment Share on other sites More sharing options...
PBR Posted August 20 Author Share Posted August 20 (edited) Hi @Niko Maresco Thank you for your reply. I followed the instruction, but I get this error: "Could not execute function call 'AutoTrigger' (3) Type mismatch. The value '2024-08-19 4:45:57 PM' (value type 'DateTime') cannot be assigned to the property 'ScriptTrigger' (data type 'String')." I named the Document Property as ScriptTrigger with type string, and my data function is named AutoTrigger, and the output is a Value. It should be noted that my IronPython script returns the calculated averages and shows them on the Y-axis of a line chart (x-axis is Time). Edited August 20 by PBR Link to comment Share on other sites More sharing options...
Gaia Paolini Posted August 20 Share Posted August 20 you need to define either a document property of type DateTime, or an output property of type string. To do the latter: output = toString(Sys.time()) 1 Link to comment Share on other sites More sharing options...
PBR Posted August 20 Author Share Posted August 20 Thank you @Gaia Paolini The error is not showing up anymore, but I don't understand why it does not trigger the ironpython script. The "refresh function automatically" is also checked. When I introduce the script to a button it works, but not through the data function. Link to comment Share on other sites More sharing options...
Gaia Paolini Posted August 20 Share Posted August 20 the data function will run if any of the input parameters change. Maybe these did not change. Also check that the data is not cached by the data function (if you edit the data function, you will see an option you want to untick). Link to comment Share on other sites More sharing options...
PBR Posted August 20 Author Share Posted August 20 The cashed is unchecked. I have a Mapchart with some shapes, and an Ironpython script to show the corresponding data for that shape on a line chart when the shape is selected. the changes are only the selection of the shapes on Mapchart. Link to comment Share on other sites More sharing options...
Gaia Paolini Posted August 20 Share Posted August 20 is it possible to send a sample dxp? Link to comment Share on other sites More sharing options...
PBR Posted August 20 Author Share Posted August 20 (edited) This is a sample dxp of my problem. I know there are other ways to establish a connection between map chart and Line chart using the markings, but they are not my purpose at the moment. Thank you very much Sample.dxp Edited August 20 by PBR Link to comment Share on other sites More sharing options...
Solution Jose Leviaguirre Posted August 20 Solution Share Posted August 20 (edited) Hello PBR, To be able to trigger your IronPython script, you also need an input parameter with an aggregating custom expression to be able to limit by marking. That way the data function will trigger when you mark a shape on your map. Create a Document property called "currentTime" or "ScriptTrigger" of any data type. Whatever makes more sense to you Create an R data function defined as Nico and Gaya described: "output <- toString(Sys.time())" uncheck allow caching define the input parameter to be 'output' as any data type define the output parameter to also be 'output' as a "Value" type Run the data function and configure the script parameters and set it to run automatically check the Refresh function automatically option set the input parameter "output" to be an Expression to form a unique selection of records limited by marking: note: to ensure the data function execution it requires an aggregation, but the data function will always output the current time as defined on the data function script. The "DateTimeNow()" statement alone might not trigger the data function limited by marking. expression: UniqueConcatenate([Shapes].[id]) & DateTimeNow() check the Refresh function automatically option limit by marked rows (use the same marking you use on your map) optionally limit also by filtered rows using one of the filtering schemes from the dropdown set the output parameter to be a Document property and select the "ScriptTrigger" or Document property The ScriptTrigger Document property will change its value every time you make a selection with marking, so now you can set that Document property to trigger your IronPython script. Sample-auto.dxp Edited August 20 by Jose Leviaguirre 3 Link to comment Share on other sites More sharing options...
PBR Posted August 21 Author Share Posted August 21 15 hours ago, Jose Leviaguirre said: Hello PBR, To be able to trigger your IronPython script, you also need an input parameter with an aggregating custom expression to be able to limit by marking. That way the data function will trigger when you mark a shape on your map. Create a Document property called "currentTime" or "ScriptTrigger" of any data type. Whatever makes more sense to you Create an R data function defined as Nico and Gaya described: "output <- toString(Sys.time())" uncheck allow caching define the input parameter to be 'output' as any data type define the output parameter to also be 'output' as a "Value" type Run the data function and configure the script parameters and set it to run automatically check the Refresh function automatically option set the input parameter "output" to be an Expression to form a unique selection of records limited by marking: note: to ensure the data function execution it requires an aggregation, but the data function will always output the current time as defined on the data function script. The "DateTimeNow()" statement alone might not trigger the data function limited by marking. expression: UniqueConcatenate([Shapes].[id]) & DateTimeNow() check the Refresh function automatically option limit by marked rows (use the same marking you use on your map) optionally limit also by filtered rows using one of the filtering schemes from the dropdown set the output parameter to be a Document property and select the "ScriptTrigger" or Document property The ScriptTrigger Document property will change its value every time you make a selection with marking, so now you can set that Document property to trigger your IronPython script. Sample-auto.dxp 2.13 MB · 0 downloads Hi Jose. That was a very wise solution. It worked well. Thank you very much. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now