Is there a way to coerce Jupyter notebook server to not edit the on-disk .ipynb when running cells (e.g. don't populate the "outputs" field) but do edit it when the user saves the file?
Related
I am hoping to include a widget in my R shiny app where the user can select a folder destination for output files to be saved in. I've tried using the shinyDirChoose and shinyDirButton, and they work, but moving through the file directory is very slow. I'd like to have the speed of fileInput and the ability to select a folder, rather than a file, as the file input (even though it would really be used for output). Is there a MIME type for folders in Windows Explorer that I could specify in fileInput? Or is there a way to speed up shinyDirChoose?
Is it possible to modify the contents of a notebook in the notebook startup code? I want to run some init code and add "header" cells to every notebook on a machine based on the code, for instance grab the hash of the current head from a local git repo, or pull a file from S3 to the local file system.
I can put a bunch of scripts, either .py or .ipy in the ~/.ipython/profile_default/startup/ directory and I'd like to modify the notebook that is currently being opened using those scripts (or some other scripts if that's possible).
According to the docs the shell has already been setup when those scripts run, so I'm thinking there should be some way of accessing, at a minimum, the local path of the notebook that was opened. I could then use nbformat (github) to modify the contents.
Alternatively I could use NotebookApp or ContentsManager to possibly modify the running notebook, but I'm not exactly sure how to do that and the notebook docs are pretty light on the actual API for those classes. This might not be possible as the init code is executed in the kernel, which does not know what the front end is, it could be the case that the kernel is connected to a console not to a notebook or to both a notebook and a console.
So
can I access the filename of the current notebook in a startup script?
should I rather be looking to modify the notebook cells through NotebookApp, FileContentsManager or some other internal class?
related
There is an open issue for template files https://github.com/jupyter/notebook/issues/332 -- this is not what I'm looking for, the template files are static, I need to modify the notebook based on the result of a computation
When exiting R Studio, I'm usually prompted to Save workspace image to ~/.RData. I accidentally clicked Save at some point, and now my Global Environment automatically loads several functions and datasets when I open R Studio. I now have to clear all objects from the workspace when I startup R Studio.
How do I remove the data (or setting) that automatically loads the saved data so that the data is not loaded on startup?
It told you the filename. Just delete that file, i.e. ~/.RData.
And you can set the default in RStudio not to restore the workspace: it's in Tools | Global options | General | Restore .RData into workspace at startup. There's another option to say not to store it.
I am using the R shiny package to build a web interface for my executable program. The web interface provides user input and shows output.
On the server background, the R script formats user inputs and saves them to a local input file. Then R calls the system command to run the executable program.
My concern is that if multiple users run the web app at the same time, it is possible that the input file generated by the first user will be overwritten by the second user's input before it is read by the executable program.
One way to solve the conflict is to ask R to create a temporary folder and generate/run the input file under that folder for each user. But I'd like to know whether there is a better or automatic way to resolve this potential conflict with shiny. For example, if use shiny fileInputs, the uploaded files are automatically stored in a temporary folder.
Update
Thanks for the advice.#Symbolix and #Mike Wise
I read the persistent data storage article before but I don't think it is exactly what I wanted. Maybe my understanding is not correct. I end up with creating a temporary folder and run my executable from there.
what is the purpose of the R temporary file that is created in every directory where a workspace is saved? What data does it contain and is it safe to delete?
That file is a holding file for save.image() while R waits for its file argument to succeed. From help(save.image) and its safe argument -
safe - logical. If TRUE, a temporary file is used for creating the saved workspace. The temporary file is renamed to file if the save succeeds. This preserves an existing workspace file if the save fails, but at the cost of using extra disk space during the save.
So the file contains the entire workspace image and it is probably best to just leave it there in case R fails to save the workspace normally.
I'm also guessing that if you see this file, R has already failed to rename the file so you may want to search for file and check its contents before deleting the temporary file.