When coding in notebook, I'm trying to show result(s) in a Single Notbook Dialog by this,

fPreview[content_,opts : OptionsPattern[]] :=
        ImageSize -> {500-10, 600-20},
        Scrollbars -> True, 
        AppearanceElements -> None, 
        Alignment -> Center],
        WindowTitle -> "Preview" <> " " <> ToString@Head@content,
        WindowSize -> {500, 600},opts]


 fPreview@Plot3D[Sin[x y],{x,-4,4},{x,-4,4}]

but once fPreview applied, there be a new Notebook Dialog, so I wonder how to modify the upper codes so that there be only One Notebook Dialog instance displaying the latest content(s)? Thanks!


1 Answer 1


There are many additional features one could need here but let's address exactly what you have asked for:

  (* I will skip styling options for clarity*)

fPreview[content_, opts : OptionsPattern[]] := With[
  { nb = CreateDialog[ content, opts] }
, ClearAll[fPreview]
; fPreview[new_, nvm___] := NotebookWrite[
    First @ Cells[nb], 
    Cell @ BoxData @ ToBoxes @ new

In general you may need to do something based on this pattern: how to generate repeatable Unique streams?, just instead of i++& it should return a log function you can use to log your results. And this way you can have many notebooks at once.

  • $\begingroup$ Thanks! It comes $Failed when fPreview executed a second time if the Notebook Dialog created at the first time was closed, I try to fix it but get failure. $\endgroup$
    – Jerry
    Commented Jan 29, 2019 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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