Is it possible to display a word or pdf file in a panel?

4,640 views
Skip to first unread message

Zhilan Ming

unread,
Aug 29, 2013, 10:53:00 AM8/29/13
to shiny-...@googlegroups.com
Hello all,
 
I have a tabsetPanel, in one tabpanel, I want to display the user manual, which would be a pdf or a word file. I know in HTML, we can construct a frame, then load the file to the frame. Is it possible to do the same thing in Shiny? Thanks!
 
Zhilan

Kirill Savin

unread,
Aug 29, 2013, 11:24:18 AM8/29/13
to shiny-...@googlegroups.com
So, what's wrong with making help in a separate html file and then adding something like includeHTML("www/help.html") inside an appropriate tabPanel in UI.R?
It's the least painful method with the best result.

Kirill Savin

unread,
Aug 29, 2013, 12:44:41 PM8/29/13
to shiny-...@googlegroups.com
However, if you absolutely have to, you can use pdf.js plugin or google drive.
Worked with google viewer:
1. Upload pdf on google drive (theoretically should work with any repository, but I haven't tried).
2. Set the sharing to everyone on the web (viewer seems to give an error otherwise).
3. Inside google drive click on uploaded file, then on the bottom click on Open button.
4. Go to File/Embed this PDF File.
5. Copy code from opened window.
6. Paste it inside UI.R in relevant tabPanel in HTML('code').
7. Don't forget to add escape \ character before every inner quotation marks.
here's an example:
                ,tabPanel
                (
                    "Help",
                    HTML('<iframe src=\"https://docs.google.com/file/d/0B3slTsWp_oiBYUxIb01xTWFlemM/preview\"
                         width=\"900\" height=\"600\"></iframe>')
                )

Joe Cheng

unread,
Aug 30, 2013, 7:16:00 PM8/30/13
to shiny-...@googlegroups.com
You could create a subdirectory called "www" in your app directory, and put e.g. a file called manual.pdf in there. Then somewhere in your UI:

tags$iframe(src="manual.pdf", width="900", height="600")

or whatever. I don't think this would work for a Word doc though...? I doubt Firefox and Chrome would display a Word doc inline.


--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Kirill Savin

unread,
Aug 31, 2013, 6:15:53 AM8/31/13
to shiny-...@googlegroups.com
Joe, this would require pdf plugin installed in a browser to show correctly. Most browsers have it though.

To guarantee the work on all platforms you should either include js viewer like pdf.js in your Shiny project or use an online viewer like the one I mentioned (works for word docs as well)

Zhilan Ming

unread,
Sep 1, 2013, 4:36:32 PM9/1/13
to shiny-...@googlegroups.com
Thank Kirill and Joe.

 It seems that to create a separate html manual file is indeed the least painful, but the html file cannot include any iframe, otherwise, it can not be displayed in Shiny. So I have to write  the manual in html, including a lot of math formulas. It's not easy to edit the file.

Using Google drive is another good way, it can even show the doc file in Shiny, however, the file must be set to public accessible. If the manual is confidential and private, this method doesn't work.

For some reason,  tags$iframe(src="manual.pdf", width="900", height="600")  doesn't work in my Shiny. I use Firefox. 

I think frame and iframe functions need to be improved in Shiny.


Zhilan


--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/buXbiqcCQWI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.

Winston Chang

unread,
Sep 3, 2013, 11:47:45 AM9/3/13
to shiny-...@googlegroups.com
On Sun, Sep 1, 2013 at 3:36 PM, Zhilan Ming <zhil...@gmail.com> wrote:
Thank Kirill and Joe.

 It seems that to create a separate html manual file is indeed the least painful, but the html file cannot include any iframe, otherwise, it can not be displayed in Shiny. So I have to write  the manual in html, including a lot of math formulas. It's not easy to edit the file.

Using Google drive is another good way, it can even show the doc file in Shiny, however, the file must be set to public accessible. If the manual is confidential and private, this method doesn't work.

For some reason,  tags$iframe(src="manual.pdf", width="900", height="600")  doesn't work in my Shiny. I use Firefox. 

I think frame and iframe functions need to be improved in Shiny.


The iframe function in Shiny just outputs HTML, so there's nothing really that can be changed about it:
> tags$iframe(src = "foo.pdf")
[1] "<iframe src=\"foo.pdf\"></iframe>"
attr(,"html")
[1] TRUE


As for displaying PDFs in an iframe, it works fine for me using Chrome, although not all browsers will be able to do it. Did you put your file manual.pdf in a www/ subdirectory? Just like when you write an index.html file by hand, you need to put in www/. See: http://rstudio.github.io/shiny/tutorial/#html-ui

-Winston

 

Ryo Eng

unread,
Mar 17, 2016, 11:38:20 AM3/17/16
to Shiny - Web Framework for R
Its work, thanks lot buddy...

2013年8月30日金曜日 1時44分41秒 UTC+9 Kirill Savin:
Reply all
Reply to author
Forward
0 new messages