# PlutoUI Print only prints last line. How can I make it print normally?

**URL:** <https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979>\
**Category:** New to Julia\
**Created:** [August 7, 2021, 4:01am UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979 "2021-08-07T04:01:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![cybervigilante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cybervigilante/32/26687_2.png) [@cybervigilante](https://discourse.julialang.org/u/cybervigilante)\
**Post date:** [August 7, 2021, 4:01am UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/1 "2021-08-07T04:01:14Z")

</div>

I’m trying to print a multiline figure in Pluto. println only goes to the REPL, and although Print from PlutoUI prints in the notebook, it only prints the last item. That is, if I do

```julia
begin
	Print("GOK")
	Print("\n")
	Print("Souffle")
	Print("\n")
	Print("GARK")
end

```

The result is GAR, with Souffle and GOK being lost. Even printing \n doesn’t help, which is odd.

How can I make Print behave as one would expect, if possible?

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [August 7, 2021, 6:10am UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/2 "2021-08-07T06:10:20Z")

</div>

Pluto shows the return value of each cell in the notebook, not the output of stdout (which is shown in the REPL where Pluto has been started). Thus, it is best to re-arrange your code, e.g. (each line in a separate cell)

```julia
"GOK"

"Souffle"

"Gark"

```

If you really need to show REPL output in a notebook, you can do

```julia
PlutoUI.with_terminal() do
   println("foo")
end

```

In the future, a feature like [https://github.com/fonsp/Pluto.jl/pull/437](https://github.com/fonsp/Pluto.jl/pull/437) could be used to display REPL output in a notebook.

---

<div class="post-metadata">

**Author:** ![cybervigilante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cybervigilante/32/26687_2.png) [@cybervigilante](https://discourse.julialang.org/u/cybervigilante)\
**Post date:** [August 7, 2021, 3:07pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/3 "2021-08-07T15:07:38Z")

</div>

That wouldn’t work too well for what I’m doing. That was just a test for a function with a loop that prints out a figure but wasn’t working with Print, and I’d still get overwriting. I can’t write a loop in separate cells. Thanks for reminding me about with\_terminal, although it’s awkward when you just need an advancing Print. What PlutoUI needs is a Println function to dupe println the way they now dupe print. Print is really stubborn. I even tried Print(“something\n”) and was sure that would work but it defeated me. I avoided with\_terminal since it looked like a do loop and I couldn’t figure it out, but of course just found out it’s a more verbose mapping function. (I’ll stick with x → x^2 since I avoid typing.) 😜

---

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [August 7, 2021, 3:25pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/4 "2021-08-07T15:25:04Z")

</div>

You could use an IOBuffer for something like that, works both in a single block and between different cells (not sure if that was what you wanted):

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/c/9cb7d6d23b913c550d6ae12b7904fff0d67fae72.png)

```julia
# ╔═╡ 6bb96b04-1adf-43c9-bd2a-2165cb6b50c5
asd = IOBuffer()

# ╔═╡ 5630b586-ff96-4de4-bc31-fdddc56099f7
println(asd,"TEST1")

# ╔═╡ e724a2d8-f0fc-43d6-9df6-43a45236a656
println(asd,"TEST2")

# ╔═╡ 206ea655-5a74-414f-b0af-f353c0b690ec
String(take!(asd)) |> Text

# ╔═╡ f8fac3f5-1dc0-493a-8c74-910675f17d07
begin
	lol = IOBuffer()
	println(lol,"TEXT1")
	println(lol,"TEXT2")
	take!(lol) |> String |> Text
end

```

---

<div class="post-metadata">

**Author:** ![cybervigilante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cybervigilante/32/26687_2.png) [@cybervigilante](https://discourse.julialang.org/u/cybervigilante)\
**Post date:** [August 7, 2021, 3:43pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/5 "2021-08-07T15:43:07Z")

</div>

> [@disberd](#):
>
> ```julia
> begin
> lol = IOBuffer()
> println(lol,"TEXT1")
> println(lol,"TEXT2")
> take!(lol) |> String |> Text
> end
> 
> ```

Thanks. also works. with\_terminal works but for some odd reason is presenting the result in a big, ugly gray box, when I just want a clean pic rendered. Now, I just have to get the mess into a loop, but it’s all fun. IOBuffer just gives me a clean result. Hmm, just tried IOBuffer in a loop and it doesn’t print. Back to square one. I’ll do something else entirely like saving the whole print-image to a matrix, to print in one go, since Print needs some work (like a Println function) Ah, finally figured it out. Just construct a multiline quote:  
Print(“”“The rain in Spain  
falls gently  
on the plain.”“”)

The rain in Spain  
falls gently  
on the plain.

That works, and it’s really simple. Now I just have to be sure I can construct a multiline quote with carriage returns, in a loop. Not having any luck with that, but I’ll stubborn it out.

Later: finally got a technique that works, just have to simplify it into a function I put in config

```julia
begin
	pho = "The rain\n"; qup = "In Spain\n";blar="Falls gently on the plain.\n"
	dummy = """"""
	for word in [pho,qup,blar]
		dummy *= word
	end
	Print(dummy)
end

```

The rain  
In Spain  
Falls gently on the plain.

 ![withterminal](https://global.discourse-cdn.com/julialang/original/3X/0/6/06ff89d77e45ae0880b7cfdbc9943b8c6dab2867.png)

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 7, 2021, 5:50pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/7 "2021-08-07T17:50:44Z")

</div>

use Jupyter?

---

<div class="post-metadata">

**Author:** ![disberd](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@disberd](https://discourse.julialang.org/u/disberd)\
**Post date:** [August 8, 2021, 8:37am UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/8 "2021-08-08T08:37:06Z")

</div>

Nice that you found out the solution that suits you, but for posterity’s sake, what was the use case that caused the IOBuffer to not work in your case?

I tried putting it in a for loop and didn’t see any issue:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/8/c8d0b66e4706cc4e0d90f2039c44c8c3015de8ba.png)

---

<div class="post-metadata">

**Author:** ![cybervigilante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cybervigilante/32/26687_2.png) [@cybervigilante](https://discourse.julialang.org/u/cybervigilante)\
**Post date:** [August 8, 2021, 4:48pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/9 "2021-08-08T16:48:44Z")

</div>

I do, but I like some of the features of Pluto, esp dynamic HTML output. It has a few oddities I’m getting used to, but Print() needs work. Anyway, here is my final hack to fix Print()

“”“Make PlutoUI’s Print(), print any number of arguments as a vertical list, without disappearing all but the last as it normally does, including numbers and basic vectors. It doesn’t like mixed-type vectors (bad idea anyway), anonymous functions, or complex stuff, but that’s a flaw in string(), not JPrint.”“”

```julia
function JPrint(args...)
	dummy = """"""
	for arg in args
		dummy *= string(arg)*"\n"
	end
	Print(dummy)
end

```

JPrint(“bim”,“baw”,“fallifaw”,“fartsy”,“artsy”,7,[3,4,14],[“all”,“good”,“dogs”,“eat”,“shoes”])

bim  
baw  
fallifaw  
fartsy  
artsy  
7  
[3, 4, 14]  
[“all”, “good”, “dogs”, “eat”, “shoes”]

---

<div class="post-metadata">

**Author:** ![cybervigilante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cybervigilante/32/26687_2.png) [@cybervigilante](https://discourse.julialang.org/u/cybervigilante)\
**Post date:** [August 8, 2021, 4:55pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/10 "2021-08-08T16:55:23Z")

</div>

Simplified version:

“”“Make PlutoUI’s Print(), print any number of arguments as a vertical list, without disappearing all but the last as it normally does, including numbers and basic vectors. It doesn’t like mixed-type vectors (bad idea anyway), anonymous functions, or complex stuff, but that’s a flaw in string(), not JPrint.”“”

```julia
function JPrint(args...)
	dummy = """"""
	for arg in args
		dummy *= string(arg)*"\n"
	end
	Print(dummy)
end

```

JPrint(“bim”,“baw”,“fallifaw”,“fartsy”,“artsy”,7,[3,4,14],[“all”,“good”,“dogs”,“eat”,“shoes”])

bim  
baw  
fallifaw  
fartsy  
artsy  
7  
[3, 4, 14]  
[“all”, “good”, “dogs”, “eat”, “shoes”]

---

<div class="post-metadata">

**Author:** ![cybervigilante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cybervigilante/32/26687_2.png) [@cybervigilante](https://discourse.julialang.org/u/cybervigilante)\
**Post date:** [August 8, 2021, 11:55pm UTC](https://discourse.julialang.org/t/plutoui-print-only-prints-last-line-how-can-i-make-it-print-normally/65979/11 "2021-08-08T23:55:24Z")

</div>

Okay, simplest way yet to make Print do the right thing:

“All  
good  
dogs  
eat  
shoes” |\> Print

All  
good  
dogs  
eat  
shoes

Not sure why single quotes are acting like double quotes, but it works.  
I’m done fooling with this. Back to learning Julia 😃
