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.
- New Project
Create a new project to store and share snippets
- New Snippet
Create and store a new snippet in Anaconda Cloud
- Filters
Apply filters to efficiently locate snippets in your catalog
- My Snippets
A collection of all your cloud projects and their nested snippets
- User Snippets
Projects to which you have access, owned by other individuals
- Organization Snippets
Projects to which you have access, owned by organizations
- Project actions
Edit, delete, and share projects
- Snippet actions
Edit and delete snippets
- 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:
Click + New Project.
Enter a unique title for your project and an optional description.
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.
(Optional) Provide access to your project by inviting users from one of your organizations.
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.
Click + New Snippet.
Under Project, select an existing project to house your snippet.
Under Snippet Title, provide a title for your snippet.
Select a language, then enter your code in the code editor. Alternatively, click + Add From Grid to add existing code from your workbook.
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:
From the Toolbox home screen, open Visualize with Python.
Click New Chart, then select a chart type.
Select the source range and adjust the chart settings from the Setup tab, customize the chart from the Design tab, and then open the Code tab.
Click Save as code snippet to open the code in Code Snippets.
Select a project to upload the snippet to, then provide a title.
If needed, edit the code to suit multiple use cases by converting labels to variables, parameterizing functions, and so on.
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:
Expand the dropdown beside your snippet. A preview of your snippet appears.
You can now import your snippet in one of two ways:
Click Run in cell.
Select the cell where you want to insert the snippet, then click OK.
Click Copy to copy the snippet to your clipboard.
In an open cell, type
=PY
, press Tab, and then paste your snippet in the green PY formula bar.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.
Expand the dropdown beside your snippet. A preview of your snippet appears.
Click Edit.
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.