Working in RStudio with deprecated Git integration (Watson Studio)

You can create R scripts and R Shiny applications in projects with deprecated Git integration.

R Shiny is an R package that makes it easy to develop interactive web applications straight from R. You can create, develope and refine Shiny apps in RStudio, whether to create a unique data visualization dashboard or publish applications into different places, for example to deployment spaces.

Creating R scripts and Shiny apps

The directory browser should be open when RStudio is launched, at the bottom right. If you are working in RStudio with Git, navigate to <your_git_repo>/assets/rstudio to ensure that all your files will sync from that folder. You can create as many subfolders as needed with different R files.

The Git extension is pre-installed, enabling access to the repository that you associated with your project at launch time and adding the Git tab to the RStudio toolbar.

The Git repository referenced in the project is cloned by the RStudio environment at launch time and can be viewed on the files browser at the bottom right of the IDE GUI in the folder called project_git_repo/<your_git_repo>. You must make all your changes to your R files in that folder to be able to sync with Git. Otherwise, it can be saved wherever you want.

Important: The clone is pulled from the Git repository branch selected at the time the project was created.

Note that if a folder or subfolder is thought to contain RShiny App files (i.e. files with the names app.R, ui.R or server.R), all files in that folder are considered to belong to the Shiny app (including .R files). Otherwise, all .R files are considered R script assets.

  1. Optional: Add collaborators to the project if you want to work on the same file with others. See Collaboration.
  2. Start working on R scipts by:
    1. Selecting New File > R Script or uploading an R file from your local machine.
    2. After you are finished working on the files, save your file changes to your local clone before you commit to the Git repository by clicking File > Save.
  3. Or start working on Shiny apps by:
    1. Clicking New File > Shiny Web App.... A new Shiny application creation window pops up.
    2. Enter a name for your Shiny application and leave userfs as the Create within directory setting. You must work in this directory or any subdirectories to enable synching with the Git repository. Both app.R and ui.R/server.R contain instructions needed to build your app and provides a sample app the user can test run.
    3. You can choose to create a single file application (app.R) if your application is simple and can be contained within one file, for simplicity.
    4. Or, you can choose to create multiple files application (ui.R/server.R) if your application is more complex and needs to have its different facets edited separately.
    5. Once you are done with configuration, click Create.
    6. You can test run your app by clicking Run App in the top right corner of the editing panel. A pop-up window will be launched displaying your application.
  4. You can use data from a dataset in your scripts or apps. Supported formats of datasets include text, CSV, SPSS, SAS, and Stata. You can use data assets already imported into the project by clicking Import Dataset under the Environment tab, or clicking File and browsing for the file under userfs/assets/data-asset, or uploading them locally by clicking Upload in the Data panel on the bottom right. You can preview the data assets in the editing panel. Note: Datasets larger than 5 MB will not be able to be previewed in RStudio.
  5. Push your file changes to the Git respository by using the Git button on the top menu bar of the main editing panel. Click Commit.
    1. Select all the files that you have made changes to and would like to push to the Git repository. Add a change description and commit your staged changes to the local clone of your repository in your RStudio session.
    2. Click Push to push your your changes to the remote repository where your changes can be seen and accessed by other users. Resolve any merge conflicts that might be caused by competing changes to files you are collaborating on. By clicking Pull in the Git actions panel, you can also pull file changes made by collaborators to your repository clone.
  6. After you have pushed your changes, sync the changes made to the Git repository with the R scripts in your project. See Syncing Git changes with your project.

    By syncing the Git R files changes with the project, you update the common shared project clone to reflect what was last pushed to the Git repository.

    The R files will appear as a project assets which you can then click to preview and promote to a deployment space. Regular code and textual files can be previewed in Watson Studio while others cannot be previewed. Note that you cannot edit, run and sync R files without first launching RStudio.

Collaboration

With the Git version control sytem added through the Git extension in RStudio, users can share their work on files in RStudio. To enable sharing when working on files, users must be added to the project as collaborators and must have access to the associated project Git repository.

To enable users in a project to collaborate on file changes in RStudio:

  1. Add users as collaborators to the project and assign them either Admin or Editor role. You can invite only users who have an existing IBM Cloud Pak for Data account. See Adding collaborators.
  2. Give all collaborators the appropriate access permissions to the project Git repository.
  3. Instruct all collaborators to create their own personal access token for the associated project repository. See Creating personal access tokens for Git repositories.

    When you open RStudio, you will see your personal Git access token in the list. Select it to begin working on the RStudio project.

Storing intermediate .rda files

You can store any intermediate files, for example .rda and .md files, log or text files files in the directory /project_data_folder/data_asset, which is part of the project clone, and hence can be accessed by all project collaborators and in R Shiny applications or jobs that run R scripts.

Working with data files

In RStudio, you can work with data files from different sources:

Adding or deleting project assets

You should upload data files to use in RStudio from the find and add data sidebar on your project's Assets page because these files are automatically added as data assets to your project.

However, if you uploaded or created data files in RStudio, you can add these files to your project as project data assets. These files must be in the Home/project_data_asset folder in RStudio. To add these files as data assets to the project:

  1. On the Assets page of the project, click the Find and Add Data icon (Shows the find data icon) and select the Files tab.
  2. Select the files you want to add to the project as assets.
  3. From the Actions list, select Add as data asset and apply your changes.

If you delete a data asset from the Home/project_data_asset folder in RStudio, the file is no longer listed in the add data sidebar under the Files tab when you click the Find and Add Data icon on the project Assets page. However it is still listed as a data asset on the Assets page of your project. To delete the entry in the data assets list:

  1. Select the data asset from the list.
  2. From the Actions menu, select Remove.

Running the script in a job

You can run the script as a job in an RStudio environment in Watson Studio or on a remote Hadoop cluster. See:

Creating a Hadoop Yarn environment

  1. The Watson Studio adminstrator needs to add the Hadoop cluster configuration to your platform.
    1. Open the drop down menu from the sandwich button on Watson Studio's home page, and click on Configure Platform.
    2. Click on Add Registration to add the Hadoop cluster to the project's configuration.
  2. Now go to your project, click on the Environments page. Click on New template to create a custom environment.
  3. After you give the custom environment a name, select Hadoop as the environment type.
  4. Select the Hadoop configuration you would like to use.
  5. A Hadoop cluster set up for R scripts needs to be able to use Yarn, as certain R scripts require usage of Yarn. If the cluster is set up correctly, a field called Execution type appears, in which the user can select Yarn as the execution type. If you do not see an option for Execution type, it is likely your Hadoop admin has not set up the Hadoop cluster and configuration file to support the R environment. Once the set up is done on the hadoop side, your admin will need to refresh the Hadoop registration before Execution Type option would be available. You can select "Yarn" to run R script.
  6. Select the language, Yarn size and Yarn container memory. These fields are bounded by the admin's settings.
  7. Click Create to complete the creation of the environment.
  8. You can change the default settings of the custom environment later by clicking on the environment under the Environments page, for example, increase or decrease the memory of the Yarn container.

Creating an app deployment

If you have an R Shiny asset saved to a project, you can promote it to a deployment space, then deploy it as an app and make the URL available to users.

To create an app deployment:

  1. From the deployment space, click the name of the saved R Shiny app you want to deploy. The asset detail page opens.
  2. From the Deployments tab, click Add new deployment.
  3. Choose App as the deployment type.
  4. Provide a name and adjust any optional settings for the deployment, then click Create Deployment to create the deployment. Optional settings you can configure include:
Setting Description
Software configuration Not configurable. It must match the version of R that you used to create the asset.
Hardware configuration Choose a hardware configuration to match your app.
Copies The number of copies to create.
Share with Choose whether to share with:
- Anyone who has the URL
- Any authenticated user (logged into Cloud Pak for Data)
- Users who are collaborators in the project

Learn more

Parent topic: RStudio