Script access

199
8
04-03-2020 12:44 PM
Labels (1)
Highlighted
Occasional Contributor

I can find my existing scripts in AGOL Contents.  Are the scripts available once you open the Notebook.  I would have expected them to be accessible through the Files are where the default home and samplesdata are or next to the Save button on the left.

Thanks

Brian 

Tags (2)
Reply
0 Kudos
8 Replies
Highlighted
Occasional Contributor

Hi Brian,

Can you give more information?

Did you create scripts within the notebook environment or are you talking about Python scripts that you had added?

Thanks,

Shannon

Reply
0 Kudos
Highlighted
Occasional Contributor

In the notebook environment.  In the files.  As shown here I see /arcgis.  Would this be a place to also opened up notebook files that I can find in Content?  Thanks.

Reply
0 Kudos
Highlighted
New Contributor III

Hi Brian,

What format are your uploaded scripts in? Are they .ipynb? If so, they are converted to notebook items upon upload and you are able to navigate to them inside your Content page and open them into a new notebook. Are you looking to import or combine existing notebook items into a new notebook? You currently cannot do this from the files tab.

As for accessing your organisation content inside the notebook, the files tab in notebooks is separate from your AGOL content and is specifically intended for use with notebooks as a working environment. If you want to search for your organisation content inside the notebook you can either use 'Add' tab:

Or the ArcGIS API for Python:

Accessing and creating content | ArcGIS for Developers 

Reply
0 Kudos
Highlighted
New Contributor III

The notebooks I'm referring to were created online.    I can find the notebooks in My Content.  What I'm asking about is once I'm in the Notebook mode, is there a way to get to my python files from within the Notebook instance or do I need to go to My Content to get to a new python program?  Am I conflating Notebooks with python programs?

Reply
0 Kudos
Highlighted
New Contributor III

Are you trying to access functions inside those other notebooks? Or are you trying to run other notebooks such that certain things are setup before you run this new notebook?

I'm not sure if this is what you're looking for but give this a try. You might be able to tweak it to get what you need:

note: I've only been able to successfully do this using the advanced notebook runtime. Currently looking into why it doesn't work in standard notebooks.

1. Install the ipynb module:

      pip install ipynb

2. Check that it installed correctly and is the latest version (0.5.1)

      pip list

3. Get the item ID of the existing notebook you want to reference in the new notebook (found in the URL of the notebook item)

4. import the notebook like so:

      import ipynb.fs.full.itemID as customName

5. You should now be able to access the functions defined in that notebook

      customName.functionName(x,y)

If instead you'd rather run the entire notebook, you could encapsulate the logic inside a main() function and call main() using this method.

I've demonstrated the workflow below. Let me know if this is what you're after.

Existing functions notebook:

New notebook to call inside of:

Reply
0 Kudos
Highlighted
Occasional Contributor

Thank you very much for the information on installing packages and import other notebooks as functions.  That is real exciting and I didn't know it could be done.  What I was asking about was much more mundane.  That is, one you have Online Notebook open, is there a way to open another Notebook without having to go to Contents.  An analogy is that you can open Samples as shown here next to Save.  It would be nice to have another button here that says My Notebooks which opens another tab in the browser with a list of you notebooks.  

Reply
0 Kudos
Highlighted
New Contributor III

Oh I see! Sorry, I was clearly overthinking it. Currently there is nothing in the UI for that but I will put forth your interest!

If you have anymore questions feel free to reach out.

Josh

Reply
0 Kudos
Highlighted
New Contributor II

Hello Brian,

You might find this useful...

As part of our effort on the Living Atlas Team to create more Notebook specific content in online, we are starting to transfer existing Python scripts to Notebooks. But we quickly found that larger Python scripts can become a little unwieldy inside a Notebook.

 

To combat this, we pull out a majority of our code and store it as Python Code Sample items in online. This allows us to manage the code using an IDE of choice, make changes, and then update the Code Sample item with the changes. All while keeping the Notebook as light as possible.

 

Here’s where it gets interesting. Now that we have an online Python item, we can use a little Python logic in the Notebook to access the Code Sample, download it, and unzip the contents to the ‘/arcgis/home’ folder. Where it is managed and accessible across all of your Notebooks via the Kernel. The Notebook item below contains a Cell with two functions, one to manage the item contents in the home folder and another to remove it if you no longer need or want it. The manger can even update the imported module when it detects a change the next time you run the Notebook or trigger the manager.

 

Basically, it maintains a local cached copy of the Python item content in your account file folders. You just tell it what Item Id to pull down and manage. Then, simply Import the module(s) as usual to get at the Classes, Functions, and properties you are accustom to.

 

Best part about this technique, you can leverage any Python Code Sample that is accessible, enabling you to access reusable libraries and one off code alike.

Sample Notebook titled 'Manage Notebook Code Dependencies':

https://www.arcgis.com/home/item.html?id=46c7512604654601ab4338f9299c5414

Regards, Paul