Data360 Analyze

 View Only
  • 1.  Running R (shiny)

    Posted 01-13-2021 18:29

    Hi,

    I have an R script which invokes a certain popup window when it completes execution - based on shiny.
    The next step is to utilize Analyze to orchestrate this process.
    I have gotten the R node pack installed on the environment, such as this: https://support.infogix.com/hc/en-us/articles/360057995373-Download-R-Node-Pack-3-6-5

    The question is: When the entire R script is populated into an R node, the execution completes (which we have tested it to work with R studio on the same machine, and signifies that execution is without error).... but the app does not appear.
    Is there a way I can make this work?



  • 2.  RE: Running R (shiny)

    Posted 01-13-2021 18:32

    I'm running the Desktop version of Analyze (v.3.6.5).



  • 3.  RE: Running R (shiny)

    Employee
    Posted 01-14-2021 04:44

    As a test I used the Hello Shiny example on the Shiny tutorial webpage:

    https://shiny.rstudio.com/tutorial/written-tutorial/lesson1/

    The Shiny package was installed into the R environment per the instructions on the webpage. 

    As with any use of the R node, the Rserve server must be started in the R console before using the R node.

    The R node was configured as follows:

     

    The components of the Hello Shiny application in the tutorial were copied into a text editor. The Shiny application script was then saved in the specified directory as the file "app.R".

    When the R node was run, the Shiny application was opened in a new browser tab.

     

    However, when the browser tab was closed, the R node continued to run. Using the 'Stop' button on the Analyze menu causes the node to generate an error. Also, when the R node was re-run the Shiny application was not displayed. To get the application to launch again it was necessary to end the rserve.exe task in the Taskmanager and then re-start it in the R console. 

    To overcome this issue the Hello Shiny example was modified to stop the application when the browser is closed. This allows the execution of the script in the R environment to complete, which in turn enables the R node to also complete successfully.  The server component of the script was changed to include the session attribute and a function was defined to stop the application when the sessionEnded event is detected.

     

    When the modified script is used and the Shiny application's browser tab is closed, the R node completes successfully.

    An example data flow is attached (requires Analyze 3.6.0 or above). Note that it is necessary to ensure the R node library node is located within your My Documents directory. You may need to ensure the library search paths are set to include the My Documents directory.

    Note: The data flow does not contain the R node library node dependency (ensure you have installed it on your system before attempting to import the data flow).

     

    The modified Hello Shiny application script is also attached. The appDirPath specified in the R node script should be changed to correspond with the directory where the Shiny application script has been saved.

    The R node's RScript property contents are also attached for completeness. Note, the script assumes the R Node has been augmented to have an input pin ('in1') and an output pin ('out1').

     

    Limitations: The ability to launch a Shiny application from within Analyze is likely to be limited to the Desktop edition. The functionality is unlikely to operate on an Analyze Server instance (Linux or Windows Server).

     

    Attached files

    R_Node_Launch_Hello_Shiny_Example--share - 14 Jan 2021.lna
    app.R
    R_Node_Launch_Shiny_App_RScript_Contents.txt

     



  • 4.  RE: Running R (shiny)

    Posted 01-14-2021 12:40

    Thanks Adrian for the clear explanation.