简体   繁体   中英

How to safely use a tempfile in a Spotfire IronPython script for web use?

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM