3
$\begingroup$

I use utility below to share my notebooks to the cloud. One downside is that they show up in the list as UUD's and have Name: Unnamed in the hover status. Ideally there would be some kind of connection to the notebook I snapshotted it from, any suggestions?

deploy:=Module[{result,notebookPath},
notebookPath=$MachineName~StringJoin~":"~StringJoin~NotebookFileName[];
Print[notebookPath];
result=CloudDeploy[SelectedNotebook[],Permissions->"Public",SourceLink->None];
CopyToClipboard[result[[1]]];
result
];

enter image description here

Update: based on the answer, I modified my deploy as follows. This prints full local path of the notebook before saving to cloud, and uses filename as the name of cloud object.

(* Deploys current notebook, returns URL object *)
deploy:=Module[{result,notebookPath,notebookFn},
notebookPath=$MachineName~StringJoin~":"~StringJoin~NotebookFileName[];
notebookFn=FileNameSplit[NotebookFileName[]][[-1]];
Print[notebookPath];
result=CloudDeploy[SelectedNotebook[],CloudObject[notebookFn],Permissions->"Public",SourceLink->None];
CopyToClipboard[result[[1]]];
result
];

Another update: the recipe above will overwrite previous snapshots of the same notebook. Modify to include timestamp as part of name:

(* drops filename extension if present *)
dropExtension[fn_]:=(
toks=StringSplit[fn,"."];
If[Length[toks]>1,
StringRiffle[toks[[;;-2]],"."],
fn]
)
(* Deploys current notebook, returns URL object *)
(* TODO: add support for notebooks with no name (current gets StringSplit failed) *)
deploy:=Module[{result,notebookPath,notebookFn,uniqueFn,url,url2},
(* print out machine name + path + date *)
notebookPath=$MachineName~StringJoin~":"~StringJoin~NotebookFileName[];
notebookFn=FileNameSplit[NotebookFileName[]][[-1]]; (* just get basename *)
notebookFn=dropExtension[notebookFn];
uniqueFn=StringJoin[notebookFn,"_", timeString, ".nb"];
Print[notebookPath];
Print[DateString[]];
(* todo, also upload and link current notebook? *)
result=CloudDeploy[SelectedNotebook[],CloudObject[uniqueFn],Permissions->"Public",SourceLink->None];
url=result[[1]];
url2=URLShorten[url];
CopyToClipboard[url2];
url2
];
$\endgroup$
5
$\begingroup$

You need to specify a CloudObject like so:

CloudDeploy[SelectedNotebook[],CloudObject["Your Name Here"],...]
$\endgroup$
  • $\begingroup$ One gotcha I discovered, using notebook filename as CloudObject name will overwrite all results of all CloudDeploy instances from this notebook. $\endgroup$ – Yaroslav Bulatov Apr 27 '17 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.