3
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ I suppose I can solve public URL invalidation if I save notebook to cloud, and then never edit it again $\endgroup$ Apr 7, 2017 at 18:44
  • $\begingroup$ 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. $\endgroup$
    – C. E.
    Apr 7, 2017 at 20:50
  • 1
    $\begingroup$ Thanks, I was able to do something like what I wanted using CloudDeploy[Notebooks[][[3]], Permissions -> "Public"] $\endgroup$ Apr 8, 2017 at 0:08

1 Answer 1

1
$\begingroup$

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
];
$\endgroup$
1
  • $\begingroup$ You can also deploy using your username. e.g. CloudDeploy[xxx, "user:b3m2a1/path/to/file"]. That will then give you the public URL. $\endgroup$
    – b3m2a1
    Dec 4, 2017 at 0:15

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.