How I make my Jupyter notebook script locked? - jupyter-notebook

I have multiple scripts using the IRkernel on Jupyter notebook. I have to put them on a server, but I only want that people can run it, not editable or deletable.
I have already tried things, mainly by modifying the metadatas like that :
{
"deletable": false,
"editable": false,
"trusted": true
}
But when it would be on the server, others people can modify the metadatas, so it is not really what I want.
Is there a way to make my script fully locked and that nobody can editable it ?

Related

Is there a way to save the rendered node locations obtained by the layout algorithm?

When I open the saved HTML network file, it takes quite some time to load my network of a few thousand nodes. Would it be possible to save the node locations to avoid running the network layout algorithm whenever I open the file?
This is more of a manual solution, but it should work:
Render Graph in Browser => F12 Console
network.storePositions();
console.log(JSON.stringify(data.nodes.get()))
Copy output to clipboard
Edit html file/ cp html to version_static.html
Comment out loadbar div
Comment out loadbar js/css (optional)
Set physics options to false
"physics": {
"enabled": false,
"repulsion": {
goto nodes = and copy output from 1) to the vis.DataSet array
Save and done!
(Happy to collaborate on some sort of automation for this)

Script to guarantee app deploy using rsconnect:deployApp

I am able to deploy my shiny app with:
rsconnect::deployApp(appName = 'Test', launch.browser = FALSE, forceUpdate = T)
However, it does not always successfully deploy the app. I plan to have this run in a script as a Scheduled Task, and want to make sure the deployApp finishes successfully (if the process doesn't succeed, try again).
I imagine you could place this in a while loop, but I am not sure how to include script that would recognize if the function executed successfully or failed. Anyone have ideas?
Error Messages:
Preparing to deploy application...DONE
Error: $ operator is invalid for atomic vectors
As I say in the comment above, I really don't think this is a good idea. To do it safely and robustly will take a lot of work. And the error message you quote above looks pretty "uncontrolled" to me, so I suspect it's got more to do with a problem in your app than a temporary issue with the publishing process. In which case, you will be in an infinitely loop unless you take steps to prevent it. Have you investigated what your publish record and remote deployment log tell you?
That said, this would be my approach if I had to do it.
Create a flag, deploymentFlag, say, in the global environment and set it to FALSE.
Write a function, onDeploymentFailure() say, which sets deploymentFlag to FALSE.
Wrap you call to deployApp in a while loop like this
while(!deploymentFlag) {
deploymentFlag <- TRUE
rsconnect::deployApp(
...,
on.failure=onDeploymentFailure,
logLevel="verbose",
recordDir=<some dir>
)
if (!deploymentFlag) {
...interrogate the publish record to try to determine what went wrong,
and correct it if possible...
}
}
For safety, especially whilst developing and testing, I'd make sure that each attempt wrote a different publish log and I'd limit the maximum number of attempts to a very small number: 1 to start with, then 2 or 3 after I'd solved the initial problems, and so on.

How to recover accidentally deleted cells in Jupyter Notebook

I'm working in a .ipynb file in VSCode and I tried to undo some lines by using ESC + Z, but for some reason either I undid too much or I pressed something else, but around 30 of my cells all got deleted. I don't know how to redo and I'm scared I lost all my work!
How can I recover these cells???
Thanks
edit: I found the code that I've run using %history but I was hoping to get my Markdown cells as well because I wrote a lot of information there
edit 2: I noticed that my cells weren't just deleted, but my files actually just changed to a different spot in history, as my first few cells contained something different than it did before the cells disappeared. Does that change the answer to this question at all?
I did post a workaround to recover some stuff, but I'd still appreciate if someone let me know what happened in my 2nd edit, thanks!
If you hit the 'Z' key it will undo moves and deletes. Note, not CTRL+Z, but 'Z' by itself. link to the GitHub issue.
This happens constantly for me. So incredibly annoying! It happens when I hit or mishit CMD+Z. No amount of ESC-Z will recreate the deleted cell. Nothing in any menu have so far recreated the lost. I have deleted all shortcuts for 'delete cell' but it makes no difference at all. Just about to give up on VSCode for this reason alone.
I had a similar issue where I was hitting CTRL+Z outside of the cell when I thought I was inside the cell (usually because running current cell makes you lose cell focus).
Sometime it just "undid" the last created cell somewhere else in my notebook, and I actually lost some cells because I didn't realized right away what happened and just continued working.
I thought I would share my solution to this problem (because Google sent me on this post, and more people might be interested).
Redefining the Keyboard Shortcuts worked for me.
I removed the CTRL+Z shortcut when I'm not inside a cell (you can still access it with the menu Edit > Undo). I did the same for CTRL+SHIFT+Z, and so on.
To do this, I added theses rules to my keybindings.json:
{ "key": "ctrl+z", "command": "-undo" },
{ "key": "ctrl+z", "command": "undo", "when": "!notebookEditorFocused || inputFocus" },
{ "key": "ctrl+shift+z", "command": "-redo" },
{ "key": "ctrl+shift+z", "command": "redo", "when": "!notebookEditorFocused || inputFocus" },
{ "key": "ctrl+y", "command": "-redo" },
{ "key": "ctrl+y", "command": "redo", "when": "!notebookEditorFocused || inputFocus" },
I also removed the Z shortcut from Jupyter extension because I don't like it.
{ "key": "z", "command": "-undo", "when": "notebookEditorFocused && !inputFocus" },
This solution worked for me:
Open the command pallet (ctrl+shift+p on windows)
Select the "Undo" command
Not sure why it works. Does vscode disable the ctrl-z shortcut when outside a cell?
Ok, this is crazy but since I'm in Visual Studio Code, I tried right clicking on my .ipynb file and clicking "Convert to Python Script".
This recovered every single line including Markdown Code that I had before I did something to delete my cells.
Might be worth a try if you deleted your Jupyter Cells in Visual Studio Code
I found a way to get the lost cells back, which saved me an enormous amount of time as I did not have to recreate those cells. If you open the timeline (bottom left corner of the screen), you can go back in time when you still had those cells, copy the content and paste it in a new cell.
Update: you might have to upgrade to the latest version if Timeline is not available for you.
%history is a life saver but i will also note: When you run %history not all the code will show, given the amount of lines - you must navigate to the output file where you will see all the history, it is displayed there. The option to open the output file is usually given at the top of the page in VS code anyway.
I came to this thread after facing a similar situation as I lost a day's work as well but, I wasn't going to give up!
So, if you have setup Auto Save on VS Code and have wsl2 enabled and are using VS code from wsl, you have to navigate to this path
> \\wsl.localhost\Ubuntu\home\<user-name>\.vscode-server\data\User\History\.
or simply do
cd (to go to root path)
type explorer.exe . (this will open file explorer)
Navigate to .vscode-server\data\User\History\.
There will be multiple folders, pick one for the file you want to restore and Voila!
just click Z in windows. This saves my a lot of pain. it happens sometimes

Return Key in Edit Command Mode Shortcuts - Jupyter Notebook

While willing to write ↩a as a new shortcut for the run all cells above command I could not find how to specify the return symbol in Jupyter Notebook.
Writing return-a or ↩-ain the Edit Command Mode does not work and the modifier is not specified in the help dialog.
Any idea?
Return is not a modifier so shortcut like ↩-a make little sens (pressing enter and A at the same time. ↩,a meaning Return key followed by A key make more sens, but Enter is so pervasive for many actions that it is not usable in user shortcuts. I would suggest you to open an issue on jupyter/notebook on GitHub to ask for return to be added as a convenient way to map to ↩ , though even if we do that we can't guaranty that it will work. If you are willing to try to code that yourself, have a look at keyboard.js, the mapping from enter to displaying ↩ is already done in quickhelp.js, for mac at least.

PDF Access Issues When Saving Files in FileMaker

When I run scripts that save layouts as PDFs in FileMaker Pro v11, the PDFs are not accessible to my colleagues. Adobe opens and tells the user that there was an error and Access was Denied. Is there a way to alter settings, either in FileMaker or Adobe that will allow myself and my colleagues to save records as PDFs in FileMaker so that we will all have access to them?
As a side note, we can Print, choose Adobe as the printer and then save that way with no problem, however the point of the scripts is to make the whole process streamlined to the click of a button. When we use the Print script step so that Adobe is automatically chosen, we still run into the issue of having to manually save, making the 'print' scipt step a non-solution.
Here is the portion of the code that saves the PDF:
Save Records as PDF [ File Name: “$folder/$filename”; Current record ]
[ Document - Compatibility: Acrobat 7 and later ]
[ Pages - Number Pages From: 1; Include: All pages ]
[ Security - Printing: High Resolution; Editing: Any except extracting pages; Enable copying; Enable Screen Reader ]
[ Initial View - Show: Page Only; Page Layout: Single Page; Magnification: 100% ]
[ Restore; No dialog ]
According to the docs, Save Records as PDF:
Note: In order to save records as a PDF file, your privilege set must include Allow printing, or you must select Run script with full access privileges in the Edit Script dialog box.
That is,
Change the users privelege to allow printing:
Manage > Security > Privileges Sets (and for each set you can check Allow Printing).
Check "Run the script with full-access privileges" in the edit script page.
I would note, sometimes you may not want users to be able to print everything, and you may not want to run the entire script with full access privileges, so I will offer a third solution:
3. Call a sub-script whose sole purpose is to save as PDF,
check its "Run script with full access privileges" box.

Resources