holzschu / Carnets

Carnets is a stand-alone Jupyter notebook server and client. Edit your notebooks on the go, even where there is no network.
https://holzschu.github.io/Carnets_Jupyter/
BSD 3-Clause "New" or "Revised" License
546 stars 31 forks source link

Import csv files, and understanding folders on ipad #303

Open Crafty-A opened 1 year ago

Crafty-A commented 1 year ago

Hi, firstly thank you for creating such a great product! I was using Carnets Plus, but for some reason it wouldn’t let me save notebooks. So I deleted the app and re downloaded it, now I can save notebooks, but it saves the files in

private/var/mobile/Containers/Data/Application/DC07BEDF-41B3-4762-ACE3-6DBE8A133E60/Documents/

I can’t seem to work out how to change it, and have tried the other solutions in this forum but can’t get anything to work.

I have saved all my files in On My IPad/Carnets Plus/xxxx but I can’t seem to load csv’s into my notebooks. I have tried various file paths.

I also couldn’t work out how to unlock directories, I see the fold with the unlocked symbol on it, but I just get into the folder and can’t see what to do next. Everything is greyed out.

Any help would be amazing!

holzschu commented 1 year ago

When you start Carnets, it opens a file browser, that looks very much like the Files app (there is a "Recents" tab, which shows all the files recently opened, and a tab where you can select the location of the notebook. Type on the top left corner to switch between the two).

When you create a notebook, it is created in the directory that was displayed at the time, which might not be where you want it. I would recommend starting with creating notebooks in "On my iPad/Carnets Plus". The directory you showed could correspond to the location of "On my iPad/Carnets Plus", that's how all apps are stored on iOS.

To load CSV files, you need to use relative file paths. For example, have the notebook and the data file in the same directory, and use open("datafile.csv"). You also need to have read-write access for that directory. If both the notebook and the data file are in "On my iPad/Carnets Plus", that is the case. If you placed them in another place, then you need to grant Carnets read-write permission for that directory using the "unlock folder" in the top right corner. Another common issue with CSV files is that iOS has changed the quote marks to curly quotes, which confuses Python (" or ).

I'm not sure I fully understood your questions. If this doesn't help, please don't hesitate to come back with further explanation (and possibly screenshots).

Crafty-A commented 1 year ago

Thanks, for coming back so quickly. That makes more sense to me now that it uses the same directory as the notebook. I have now tried the solution above but get the following error

Permission denied: ICloud Drive.ipynb (maybe you need to grand permission on the folder) Permission denied: On My iPad\Carnets Plus.ipynb (maybe you need to grand permission on the folder)

I click on the icon at the top right and press done on the folder, it then resets the kernel with the new permissions but then it still doesn’t give me the permissions.

Thanks again

holzschu commented 1 year ago

Thanks for the additional information. I am checking the source code to understand what is raising this alert. The filenames in the alerts do not make sense, and they might be a clue.

I suspect that there is something like this: you cannot grant permission to the entire "On My iPad" directory, or to the entire "iCloud Drive" directory (even though you can create individual files there). You have to get at least one level down in the hierarchy (say, "On My iPad/Carnets", or "iCloud Drive/Documents") to get to a directory where you can grant access.

If that isn't the issue, can you send me screenshots of the errors? I could gather more information from how they appear.

Crafty-A commented 1 year ago

Screenshot 2023-06-13 at 19 57 29 Screenshot 2023-06-13 at 19 56 53 Screenshot 2023-06-14 at 15 10 49

Crafty-A commented 1 year ago

Screenshot 2023-06-14 at 15 11 31

The first screen shot is where it is defaulting, then when I try and save as Carnets plus it comes up with that error, after I give permission by clicking on the top right icon and pressing done on the folder.

It resets the kernel, but still doesn’t let me save there.

Crafty-A commented 1 year ago

Screenshot 2023-06-14 at 15 11 51

Crafty-A commented 1 year ago

Then I end in the same cycle. Sorry about multiple posts it doesn’t let me put all screens in one. I think it is me doing somthing stupid rate that a bug in the programme!

holzschu commented 1 year ago

Thank you so much for the screenshots! It's a lot clearer for me now. On the second screenshot (the first one with "Save As"), try typing the name of the notebook you want after "private/var/mobile/Containers/Data/Application/DC07BEDF-41B3-4762-ACE3-6DBE8A13360/Documents/", without erasing all that. That should work.

The longer explanation: iOS is, under the hood, a Unix operating system, with an added layer for security and user interface. Jupyter comes from the Unix world, it sees the Unix part. So, for Jupyter, the notebooks are in "/private/var/mobile/Containers/Data/Application/DC07BEDF-41B3-4762-ACE3-6DBE8A13360/Documents/" (and, for iOS, Jupyter has access to that directory). That directory is equivalent to what iOS displays as "On my iPad/Carnets Plus", but Jupyter has no way to know that (it only knows of the Unix part). So when speaking to Jupyter, you need to use the Unix path (the one with ".../var/mobile/...". When you switch back to iOS (for example when you use iOS file navigator, or the Files app) you will see your files inside the folder "On my iPad/Carnets Plus".

Let me know if this answers your question.

Crafty-A commented 1 year ago

Thanks, that makes sense now. When I save the notebooks, they go into the Carnets folder, and I can read the csv files now in my notebook. Hopefully this is the final question. When I have put a folder in Carnets called “Test” and added it to the documents file path, it can’t find the folder. Is there a trick, or do I have to have it all in default carnets folder.

Thanks

holzschu commented 1 year ago

It should work with the folder named "Test". Can you post more screenshots?

Crafty-A commented 1 year ago

Hi, sorry I completely missed your reply. I think that it is working now, so not sure what I was doing wrong. Thank you again for the awesome app and all your help!