3

I am trying to export a Spotfire visualization to xlsx file. In order to export the data, I need to be able to write the visualization's data to a tempfile. The IronPython(2.7.7) script works when running as Spotfire Desktop App, since it is using the local machine's tempfile location. However, it does not work on the web since the script does not have permission to write to the server's tempfile location returned by Path.GetTempFileName().

How can I safely write to a tempfile via script for use in the web?

Script:

from System.IO import Path, File, StreamWriter
from Spotfire.Dxp.Application.Visuals import TablePlot

tf = Path.GetTempFileName()
writer = StreamWriter(tf)

# visTable is a script parameter pointing to a TablePlot
visTable.As[TablePlot]().ExportText(writer)

Error when run in web:

Could not perform action 'write_to_file'.

Could not execute script 'write_to_file': The directory name is invalid.


   at Spotfire.Dxp.Application.Scripting.ScriptService.Execute(ScriptDefinition script, Dictionary`2 scope, InternalLibraryManager internalLibraryManager, NotificationService notificationService)
   at Spotfire.Dxp.Application.Scripting.ScriptManager.<>c__DisplayClass8_0.<ExecuteScript>b__0()
   at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(Executor executor, Boolean visible, Boolean sticky, Guid stickyGuid, Boolean isHighlight)
   at Spotfire.Dxp.Framework.Commands.CommandHistory.Transaction(String displayName, Executor executor)
   at Spotfire.Dxp.Application.Scripting.ManagedScript.Execute(Dictionary`2 environment)
   at Spotfire.Dxp.Application.HtmlTextAreaControls.ActionControl.ModifyCore(Object value)
   at Spotfire.Dxp.Application.Visuals.HtmlTextArea.InteractWithControl(String id, Action`1 interaction)

IronPython Version: 2.7.7

Spotfire Version: 10.3.2.8

Edit: The builtin right click export functionality is not an option since the end goal is to inject my company's compliance information.

David C
  • 1,898
  • 2
  • 16
  • 31

2 Answers2

2

You can set the tempfile location to network drive that the Spotfire server and user both have access to.

My best suggestion is empower users to right click a visual to download the table as that is the easiest method and requires no coding.

I have achieved writing some scripts to export data as a CSV that works both in Desktop Client and WebPlayer , but It is a jumble of R , Python , Javascript and HTML. That can be found here : My Spotfire Wiki Post

Tyger Guzman
  • 748
  • 5
  • 13
  • Have you tested your tableplot to html on large data sets (~1 million rows)? If so, is there a performance drop? – David C Feb 28 '20 at 14:27
  • Yes there is definitely performance drop when using large data sets. Hence my best suggestion being to empower users to right click and download from table/crosstable visuals as spotfire shows the Loading/Processing of the export. Please don't forget to vote on my answer. – Tyger Guzman Feb 28 '20 at 19:09
  • Unfortunately, I need to add compliance information during the export, hence the reason for not using the builtin right click export. I will try using a network drive that both the server and users have access to at work on Monday. – David C Feb 29 '20 at 13:35
  • Gotcha. That would be a great feature out of the box to add header or footer info to an export. Only the PDF reports have that option but not always the best format to share. – Tyger Guzman Feb 29 '20 at 18:16
0

I use the Spotfire Javascript API to render all my analysis in HTML/ASPX pages. So for times when people need to download data , i set up a button to open a dxp page showing only the table so that users can then right click to download. This method helped to not have the data visible until needed. EVEN the Javascript API does not have an export to CSV or EXCEL only PDF , Visual (picture) , Powerpoint , and Reports(determined PDF exports)

https://community.tibco.com/wiki/tibco-spotfire-javascript-api-overview

Tyger Guzman
  • 748
  • 5
  • 13