Include the www directory of a shiny app in an R package

2,742 views
Skip to first unread message

charlott...@gmail.com

unread,
Apr 8, 2016, 10:16:04 AM4/8/16
to Shiny - Web Framework for R
Dear all,

I am trying to build a package containing my shiny app. However, as I have some images in my www directory, I try to include them in this package and I don't know how include this directory (or just images ?) in my package.

I looked at the specific topics of building a shiny app (e.g. http://deanattali.com/2015/04/21/r-package-shiny-app/) but I did not found a topic on the www directory. Moreover, as very few R packages contains images, I thus did not found the solution in other forums than shiny's forum... :'( (e.g. http://stackoverflow.com/questions/28189327/including-images-in-r-package-documentation-rd-files)

Does anyone includes images in its shiny package ?

Thank you very much for your help !!!

Cheers

Charlotte

Dean Attali

unread,
Apr 9, 2016, 4:05:22 AM4/9/16
to Shiny - Web Framework for R
If you follow the structure that I suggest in my blog post, there shouldn't be any problem if you just put an image in a www/ directory and then refer to it in your app.  I have images in a shiny app inside a package, you can see here: The image lives inside the www/ folder (link) and I refer to it with a single `img(src = "image.png")` (link)

charlott...@gmail.com

unread,
Apr 9, 2016, 11:21:05 AM4/9/16
to Shiny - Web Framework for R
Dear Dean !

Thank you very much for your answer ! I thought that it was cheating to put some additional folders in an R package (I am a beginner at building R package).

But Ok sounds great and it works perfectly !!

Again thank you for you help and congrats for your website, very helpful :)

Cheers !

cha

charlott...@gmail.com

unread,
Apr 21, 2016, 5:47:50 AM4/21/16
to Shiny - Web Framework for R
Dear Dean and others,

After two weeks of thinking, I don't understand how source an image in the code as the working directory is changing with user:

At the beginning, I paste getwd() and the path of the image in the package but when user change WD then it fails:

    output$myImage1 <- renderImage({
      list
(src = paste0(getwd(), "/www/1.png"),
           contentType
= 'image/png',
           width
= 20,
           height
= 20,
           alt
= "This is alternate text")
   
}, deleteFile = FALSE ) # eo output$myImage1

I would need to reach the path of the package within the user computer ? am I right ?

Thank you very much for any help,

Cheers

Cha

Joe Cheng

unread,
Apr 21, 2016, 6:35:49 AM4/21/16
to charlott...@gmail.com, Shiny - Web Framework for R
Use system.file("www/1.png", package="yourpackagename") to find the path to that file in your installed package.
--
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/f512c8fa-d86b-4a49-98e4-5c992527c143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

charlott...@gmail.com

unread,
Apr 21, 2016, 7:39:11 AM4/21/16
to Shiny - Web Framework for R
Thank you very much Joe !!

But It raises a problem: In the package, I enclosed the www directory in the package (below man and R directories), but when I build and source the package, the www directory disappears !!!

However, when I open the directory of the installed package of Shiny (as instance) I see that you have well enclosed  a www directory.

Do I need to put the www directory after building the package ?? When do you enclosed this www folder ? After or before building the package ?

Thanks again for your help !

Cha

charlott...@gmail.com

unread,
Apr 21, 2016, 9:37:52 AM4/21/16
to Shiny - Web Framework for R
Ok I found the solution,

To enclose additional subdirectories in R package (like www) I think we just have to create a "inst" directory and put the additional folders in it.

Again, thank you very much for your precious help.

Cha

Joe Cheng

unread,
Apr 23, 2016, 12:14:09 PM4/23/16
to charlott...@gmail.com, Shiny - Web Framework for R
Any custom directories you want to include in the package must be under an "inst" directory. For example, "inst/www". At install time this will become simply "www" (the inst folder will be removed and all its children promoted).
--
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.

saqib kareem

unread,
Aug 20, 2018, 3:37:24 PM8/20/18
to Shiny - Web Framework for R
dear all,i am looking for the solution i have custome login page as login.html file in www directory.
i want R console should open first this page.if credentials apss there and found true then move to my shiny dashboard.
how can i do this any help

vasconce...@gmail.com

unread,
Aug 26, 2018, 10:54:07 PM8/26/18
to Shiny - Web Framework for R
Can you show the code? I'm trying to do something like it, with no sucess
Reply all
Reply to author
Forward
0 new messages