Code Snippets#

Code Snippets enable you to securely upload reusable blocks of code to Anaconda Cloud. You can then provide access to other users, as well as import your code snippets to separate workbooks to repeat your efforts from any machine, anytime.

Understanding connections#

Let’s take a look at the different elements within Code Snippets.

  1. New Project

    Create a new project to store and share snippets

  2. New Snippet

    Create and store a new snippet in Anaconda Cloud

  3. Filters

    Apply filters to efficiently locate snippets in your catalog

  4. My Snippets

    A collection of all your cloud projects and their nested snippets

  5. User Snippets

    Projects to which you have access, owned by other individuals

  6. Organization Snippets

    Projects to which you have access, owned by organizations

  7. Project actions

    Edit, delete, and share projects

  8. Snippet actions

    Edit and delete snippets

  9. Running snippets

    Multiple methods for adding and running snippets in a workbook

Create a project#

When you first access Code Snippets, you are prompted to create a new project. You can think of projects as folders for storing your snippets.

You must create a project before uploading your first snippet. Create a project at any time using the following steps:

  1. Click + New Project.

  2. Enter a unique title for your project and an optional description.

  3. Designate the project owner(s) for your project. By default, you are set as the only project owner.

    Note

    Administrators and project owners are the only users allowed to edit projects. Anaconda Cloud organization administrators have full permissions for any projects owned by their organization.

  4. (Optional) Provide access to your project by inviting users from one of your organizations.

  5. Click Save.

Sharing a snippet#

You can share a snippet with others in your organization by sharing the project containing that snippet. This can be done as you’re creating a new project or at any time using the following steps:

  1. Click actions beside a project for which you have edit permissions, then click Edit.

  2. Provide access to your project by inviting users from one of your organizations.

    1. Under Your Organizations, select an organization.

    2. Under Organization Users, select a user to share your project with.

    3. Choose whether the user should have read or write access to your project.

  3. Click Save.

Uploading a snippet#

With a project in place on Anaconda Cloud, you can now create a snippet and upload it to that project. This can be done from Code Snippets or, if you want to save code generated while creating visualizations of your data, you can upload a snippet from Visualize with Python.

  1. Click + New Snippet.

  2. Under Project, select an existing project to house your snippet.

  3. Under Snippet Title, provide a title for your snippet.

  4. Select a language, then enter your code in the code editor.

    Tip

    To add existing code from your workbook to the code editor, select the pertinent cell and click + Add From Grid.

  5. Click Save to Cloud .

Your snippet appears in its assigned project folder.

When working in Visualize with Python, Anaconda Toolbox writes code to render your data as a visualization. You can then open this code in Code Snippets to edit and save to Anaconda Cloud using the following steps:

  1. From the home screen of Anaconda Cloud, open Visualize with Python.

  2. Click New Visualization, then select a plot type.

  3. Select the source range and adjust the plot settings from the Setup tab, customize the plot from the Design tab, and then open the Preview tab.

  4. The code for your plot appears under Preview Code. Click Save as code snippet to open the code in Code Snippets.

  5. Select a project to upload the snippet to, then provide a title.

  6. If needed, edit the code to suit multiple use cases by converting labels to variables, parameterizing functions, and so on.

  7. Click Save to Cloud .

Your snippet appears in its assigned project folder.

Adding snippets to a workbook#

When you’re ready to make use of your saved snippets, import them to a workbook using the following steps:

  1. Expand the dropdown beside your snippet. A preview of your snippet appears.

  2. You can now import your snippet in one of two ways:

    1. Select the cell where you want to insert the snippet.

    2. Click Run in cell.

    1. Click Copy code to copy the snippet to your clipboard.

    2. In an open cell, enter =PY and paste your snippet in the green PY formula bar.

    3. Use Ctrl + Enter/return to run the code.

Editing a snippet#

Changes made to a saved snippet in a workbook will not automatically update that snippet in Anaconda Cloud. Instead, you must make changes to the snippet directly within the Anaconda Toolbox extension.

  1. Expand the dropdown beside your snippet. A preview of your snippet appears.

  2. Click actions , then click Edit.

  3. Adjust your snippet, then click Save to Cloud .

    Note

    Changing the title of your snippet will create a new snippet, rather than updating the existing one.