PS, after some trial an error I ended up with function below which I'm mostly happy with. Usage is --
execute deploy
, it'll print timestamp and link which is public, also copied into clipboard for convenience. This deployment is a snapshot, so calling deploy
multiple times will deploy new copies of the object.
Some lessons learned:
- Exporting object, then editing it in cloud invalidates the public URL link (the link will start prompting user to sign in), hence must export snapshots and never edit them.
- Using notebook filename as name for cloud object will overwrite previous results, so generate unique names by appending timestamp to filename.
Code
(* 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 update master copy in cloud and link to it using SourceLink? *)
result=CloudDeploy[SelectedNotebook[],CloudObject[uniqueFn],Permissions->"Public",SourceLink->None];
url=result[[1]];
url2=URLShorten[url];
CopyToClipboard[url2];
url2
];
CloudDeploy
on a notebook object (that you can retrieve withNotebooks[]
). It will return a URL. Since it is a deployed object, it shouldn't have any kind of connection with the local notebook AFAIK. $\endgroup$CloudDeploy[Notebooks[][[3]], Permissions -> "Public"]
$\endgroup$