Skip to main content

Power BI

New

Serialize visual custom code (R/Python script visual, Deneb, etc.) as standalone files when saving a report using the Power BI enhanced report format (PBIR)

Vote (13) Share
Joel Miller's profile image

Joel Miller on 18 Jun 2024 11:24:44

Currently reports containing the R or Python script visual or a custom visual where the user provides their own code (such as Deneb), when being saved using the Power BI enhanced report format (PBIR), store the script/code embedded as JSON strings within the "visual.json" file for that visual, with new line characters and double quote marks in the code needing to be escaped with a backslash. For the R/Python script visual, the script code appears in a property called "source". For the Deneb custom visual, the code appears in properties called "jsonSpec" and "jsonConfig".


This custom code should instead be stored as one or more separate files that sit alongside the "visual.json" file. For the R/Python script visual, this could be a file called "source.R" or "source.py". For the Deneb custom visual, this could be files called "jsonSpec.json" and "jsonConfig.json". This solution would give report developers a better source control experience when modifying visual custom code, with the ability to easily modify code offline, and with clean diffs free of escape characters.


In the case of the R/Python script visual, Microsoft could implement this solution themselves in the PBIR serializer. In the case of custom visuals like Deneb, Microsoft should enhance the Power BI visual SDK so custom visual developers can specify that certain text-valued properties should be serialized as standalone files in PBIR mode, rather than being serialized as a string within the "visual.json" file.

Comments (2)
Joel Miller's profile image Profile Picture

Andy Clapham on 03 Jul 2024 19:41:34

RE: Serialize visual custom code (R/Python script visual, Deneb, etc.) as standalone files when saving a report using the Power BI enhanced report format (PBIR)

I wonder if they've considered yaml as a format. This would allow block scalars. But then ... yaml ... Although another benefit to externalizing source in different langauges is that IDEs can trivially recognize the language.

Joel Miller's profile image Profile Picture

Daniel Marsh-Patrick on 19 Jun 2024 02:19:10

RE: Serialize visual custom code (R/Python script visual, Deneb, etc.) as standalone files when saving a report using the Power BI enhanced report format (PBIR)

As someone very invested in Deneb's development and ecosystem, I support this idea :)One thing to consider is that Deneb will support JSON with comments (JSONC) from the next version. This is conventionally processed using a serialized format like the visual properties already used, so I would suggest that if Deneb could be supported in this manner through PBIR and changes to the custom visuals SDK, then files would be saved using a .jsonc extension, so code editors know that it should be treated as such.