From shiny, display pdf output in new browser tab?

1,461 views
Skip to first unread message

Norman Packard

unread,
May 18, 2015, 9:15:33 PM5/18/15
to shiny-...@googlegroups.com

I sometimes have graphics output (e.g. many graphs) that is best compiled and displayed in a pdf.  I would like to generate such a pdf from within shiny, then display it in a new browser window / tab using the browser's default pdf viewer.

I found Joe Cheng has given one approach to displaying a pdf by putting it in the  www directory (e.g. called output.pdf) and using a call like tags$iframe(src="output.pdf", width="600", height="900").  I have tried this, and it works quite well. It even works within a renderUI call in server.R, where the filename can be changed dynamically.

But... it doesn't have some nice features of using the browser's pdf displayer, e.g. saving to a file.

I tried replacing the tags$iframe with straight HTML, trying to pop up a new window:

HTML(paste0('<a href=http://localhost:3838/output.pdf target="_blank>" Click here for the results...</a>'))

but this didn't seem to do anything.

Thanks for any help!


Norman Packard

unread,
May 18, 2015, 9:33:41 PM5/18/15
to shiny-...@googlegroups.com
Never mind.  The tags$iframe() solution actually does use the default browser pdf viewer.  I just wasn't mousing to the right place to see the buttons.

Joe Cheng

unread,
May 19, 2015, 1:25:20 AM5/19/15
to Norman Packard, shiny-...@googlegroups.com
Your <a href> would've worked too--there's just a double-quote on the wrong side of the bracket. Also it's much easier to do:

a(href="output.pdf", target="_blank", "Click here for the results...")

On Mon, May 18, 2015 at 6:33 PM, Norman Packard <nhpa...@gmail.com> wrote:
Never mind.  The tags$iframe() solution actually does use the default browser pdf viewer.  I just wasn't mousing to the right place to see the buttons.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/c0c216aa-2dd6-4674-8f5d-36ba5c0be792%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Norman Packard

unread,
May 19, 2015, 2:22:26 PM5/19/15
to shiny-...@googlegroups.com, nhpa...@gmail.com
Thanks Joe!
Sorry to pollute the forum with buggy code.


Reply all
Reply to author
Forward
0 new messages