Jump to content
  • Question: How to import R graph build in R Studio in to Spotfire Analyst


    Question, comments and answers for this topic.

    Question:  How to import R graph build in R Studio in to Spotfire Analyst

    Hi All ,

    I am trying to integrate  R graph build in R Studio in to Spotfire Analyst .

    I have generated corrplot in R studio.Now requirement is to add it inside Spotfire.

    Any idea ?

     

    Regards,

    User

    Jun 02, 2016 - 4:10am

    User

     

    (4) Answers

     

    Answer 1: Best Answer

    You can use RinR package to execute R code in TERR. Therefore you can use that to generate plots and have them displayed in Spotfire. The best way is to have your data function output your plot image in binary format, then you can just display that in a Text Area as a Label.

    Note: This will work natively in the installed Analyst client, but will require the TIBCO Spotfire Statistics Services (TSSS) server to work on the Web Player.

    Alternatively, and this is my recommended approach, if you do have a TSSS server you can have TSSS use an R engine and don't need to use RinR (since you will be running R code natively in the R engine used by TSSS). That way both installed Analyst client and Web Player will use the TSSS server to run your R code.

    If you do go the route of not having TSSS, then here is a KB from the TIBCO support site on how to use RinR and how to generate binary image files

    • KB: 42658 How to create a graph using TERR, by calling open-source R functions via the RinR package.
    Title: 	How to create a graph using TERR, by calling open-source R functions via the RinR package.
    Description: 	TERR does not create graphics. However, you can call out to an open-source R installation to generate graphics using the RinR package. You can save the graph created in this way to a file or you can pass the graph object back into Spotfire for display as a static graph.
    Environment: 	Product: TIBCO Enterprise Runtime for R (TERR)
    Versions: TERR 1.5 and later
    OS: All supported operating systems
    Resolution: 	The following TERR code will create a graph using open-source R:
    
     
    library(RinR)
    library(Sdatasets)
    
    # If running from a Spotfire Data Function, you will need to
    # set the path to your local open-source R installation. 
    # For example:
    # pushPATH("C:\\Program Files\\R\\R-2.15.3\\bin")
    
    graph <- RGraph(
          {par(mfrow=c(3,2))
          plot(
                lm(fuel.frame$Mileage ~ fuel.frame$Weight),
                which=1:6,
                ask=F
          )},
          data=list(fuel.frame=fuel.frame),
          display=FALSE
    )
    
     
      -------------------------------  You can either add code to save the graph to file (i.e. png, jpg, etc...), for example:  -------------------------------  
     
    library(RinR)
    library(Sdatasets)
    
    # If running from a Spotfire Data Function you will need to
    # set the path to your local open-source R installation,
    # for example:
    # pushPATH("C:\\Program Files\\R\\R-2.15.3\\bin")
    
    graph <- RGraph(
          {png(file = "C:\\myplot.png", bg = "transparent")
          par(mfrow=c(3,2))
          plot(
                lm(fuel.frame$Mileage ~ fuel.frame$Weight),
                which=1:6,
                ask=F
          )
          dev.off()
          },
          data=list(fuel.frame=fuel.frame),
          display=FALSE
    )
     
      -------------------------------  Or you can return the graph as a binary object to display in Spotfire when calling the following code from a Spotfire Data Function:  -------------------------------  
     
    library(RinR)
    library(Sdatasets)
    
    #Set the path to your local open-source R installation
    pushPATH("C:\\Program Files\\R\\R-2.15.3\\bin")
    
    graph <- RGraph(
          {par(mfrow=c(3,2))
          plot(
                lm(fuel.frame$Mileage ~ fuel.frame$Weight),
                which=1:6,
                ask=F
          )},
          data=list(fuel.frame=fuel.frame),
          display=FALSE
    )
    graph <- as.raw(graph)
     
    To see a full step-by-step example of how to display the binary object as a static graph in Spotfire, please see KB article # 43727.
    Reference: 	You can read more about the functions used in the code above by typing a question mark followed by the function name at the TERR command prompt.  For example:
    
    > ?pushPATH
    > ?REvaluate
    
    Note, the RinR package must be loaded (using command 'library(RinR)') before you can access the help files for the functions in the package.
    
     

    And to display that binary image format in Spotfire here is another KB from the TIBCO Support website:

    • KB: 43727 How to display a binary object as a static graph in Spotfire.
    Title: 	How to display a binary object as a static graph in Spotfire.
    Description: 	Images (such as .jpg, .png, gif, etc.) can be stored in their binary data format and then displayed in Spotfire. This can be useful for capturing images from external applications and displaying them in a Spotfire analysis.
    Environment: 	
    Product: TIBCO Spotfire (desktop client / Analyst / Professional)
    Version: All Supported
    OS: All Supported Operating Systems
    --------------------
    Resolution: 	
    
    One example of working with binary image data is where you can use TIBCO Spotfire Statistics Services and the R engine to generate graphs in your data functions and then display those in your Spotfire analysis.  This can be useful for creating graphs in R that are not present in Spotfire. For an example of this, see KB article # 42658 on how to return graphs as a binary object using TERR through the RinR package with open-source R. The data function will use a binary property as the output parameter where your binary image data will be stored.  You can display your image in Spotfire using one of these two techniques:
    
    
    To display your image in a Text Area:
    If your binary image data is stored in a property (document, data table, or column property), such as resulting from from a data function like described above:
    
        1) Create a new Text Area with 'Insert' > 'Text Area'.
        2) Right click on your new Text Area and select 'Edit Text Area'.
        3) Click the 'Insert Property Control' icon and select 'Label'.
        4) In the 'Property Control' dialog, choose the property that contains the binary image value in either the Document Property, Data Table Property or the Column Property tab depending on the property type defined as the output parameter of your data function.
        5) Click OK.
    
    
    To display your image in a Table visualization cell:
    If your binary image data is already present in a data column, the image can be displayed in the table cell.
    
    
    Right click on the table visitation and choose 'Properties'
    Click 'Columns'.
    Choose the column that contains your binary image data on the 'Selected columns:' list.  Add your data column to the list if not present.
    In the 'Renderer:' dropdown, choose 'Image'.
    Click 'Close'.
     

    Jun 02, 2016 - 8:41am

    Sean Riley

    Answer 2:

    Hello Manisha, 

    You can refer the following links to get an idea on how to implement R graphics in Spotfire : 

    http://stackoverflow.com/questions/26294992/displaying-png-files-from-r-...

    http://www.tibco.com/blog/2015/07/23/spotfire-tips-tricks-adding-r-graph...

    Jun 04, 2016 - 8:37am

    User

     

    Answer 3:

    Regarding using stats services, we can point you in the right direction if you post back here.

    Andrew

    Jun 02, 2016 - 7:08am

    Andrew Berridge

     

     

    Answer 4:

    Do you have TIBCO Spotfire Statistics Services installed at your organisation?

    If you need the graph to be generated using Spotfire data and on demand, then you'll need to use stats services. 

    Otherwise you can export the graph as a png and then embed it in a text area.

    Andrew

    Jun 02, 2016 - 7:08am

    Andrew Berridge

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...