observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

A new "Convert to FileAttachment" Cell Menu Option #462

Open asg017 opened 2 years ago

asg017 commented 2 years ago

Is your feature request related to a problem? Please describe. Very often, I find a need to convert a cell into a file attachment, usually to "cache" a value. For example, I have a cell that does some scraping (fetch some remote URL, little bit of transformations) on the fly whenever a notebook is loaded. But, I know that at some point, the remote resource won't be available anymore. It might be an unstable 3rd party site or a localhost URL that I'm only running temporarily. But I still want the data the be available in the long run, so I'll download the data as JSON/CSV, and re-upload it as an attachment, then redefine the cell to use the fileattachment rather than the older code.

Describe the solution you'd like I'd like there to be a new cell menu option on the left hand side called "Convert to File Attachment". When I click on it, I want the value of that cell to be uploaded as a new fileattachment (maybe an option to choose JSON/CSV), then for the cell's source code to update to use that new file attachment (FileAttachment("file").json()) and comment out the previous cell definition.

Describe alternatives you've considered The manual workflow works fine: click "Download as JSON", save the file to your computer, then click on the Data icon, re-upload the file, then re-define the cell to use the new FileAttachment. But it's quite a lot of clicks (10+), it's easy to make a mistake, and it leaves you with an unnecessary intermediate file on your hard drive.

Additional context Add any other context or screenshots about the feature request here.

mootari commented 2 years ago

Related: https://github.com/observablehq/feedback/issues/175

CobusT commented 2 years ago

JSON would probably be more flexible, since CSV would have some limitations on the structure of the data...

tophtucker commented 2 years ago

One approach would be that every "Download as…" option should also let you "Copy as…" or "Upload [file attachment] as…", without any effect on editor contents.

Another approach would be something more magical where you could turn on caching for any cell, and all recomputation would be manual, and maybe it'd be a file attachment behind the scenes. (Though there are things that couldn't easily be saved, like recursive data structures or functions or whatever.)