4

Is there some utility that'll let me share current notebook to Wolfram Cloud and get public URL?

My current workflow for sharing is to make a temporary copy of notebook locally, then save it to cloud, then open it in browser and copy public link from sharing settings. I need to make a temporary copy because I noticed the public link becomes invalid if I edit the notebook and save it again in Mathematica.

Yaroslav Bulatov
  • 7,793
  • 1
  • 19
  • 44
  • I suppose I can solve public URL invalidation if I save notebook to cloud, and then never edit it again – Yaroslav Bulatov Apr 07 '17 at 18:44
  • I don't have much experience with the cloud functions, but from my reading of the documentation it should work to use CloudDeploy on a notebook object (that you can retrieve with Notebooks[]). It will return a URL. Since it is a deployed object, it shouldn't have any kind of connection with the local notebook AFAIK. – C. E. Apr 07 '17 at 20:50
  • 1
    Thanks, I was able to do something like what I wanted using CloudDeploy[Notebooks[][[3]], Permissions -> "Public"] – Yaroslav Bulatov Apr 08 '17 at 00:08

1 Answers1

1

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
];
Yaroslav Bulatov
  • 7,793
  • 1
  • 19
  • 44
  • You can also deploy using your username. e.g. CloudDeploy[xxx, "user:b3m2a1/path/to/file"]. That will then give you the public URL. – b3m2a1 Dec 04 '17 at 00:15