10

Is there any way to generate documentation for a R shiny application?

It becomes very hard to maintain a shiny application without documentation.

It seems that all the eco-system of tests/documentation is created for an R package structure. Maybe we can emulate/extend this behavior for a shiny application?

An example :

A reactive expression is typically an R shiny element taht can contain complex data structure.

   filtered_dat <- reactive({ 
      dx[ NAME == input$crr & TOU == input$tou & 
            PlotYear == input$year. & PlotMonth == input$season]
    })

To give more context, I am here in the context of building a complete web application using R shiny. All the business-logic is wrapped in a separated package(s).

For testing Ui I think it is complicated ( one can use Rselenium for example) , but generating doc from roxygen2 comments is just parsing. It should be easy to have such tool.

agstudy
  • 119,832
  • 17
  • 199
  • 261
  • 1
    What exactly are you documenting? Much of the actual R code called in a Shiny application could live it it's own package with its own docs. – joran Jul 08 '15 at 22:36
  • @joran good point. But For me Shiny application is just a we application. Even in real web application you call external librarians but you still have the possibility to document it. What about tests? – agstudy Jul 08 '15 at 22:40
  • If you separate the the logic and UI layers rigorously, and put the logic in testable libraries, then you have a nice division that should be easy to explain and document. Not sure you could do unit tests on the UI layer in anyway, but that is always a problem anyway. Similar to joran's suggestion. – Mike Wise Jul 08 '15 at 22:45
  • 1
    @agstudy Did you ever find a solution to this that you were looking for ? – steveb Jun 25 '17 at 03:38
  • @steveb create a package and put all functions within it. function can have `input` , `output` as parameters. – agstudy Jun 25 '17 at 03:57
  • @agstudy Thanks for your quick reply. Do you pretty much mean, do minimal coding in the shiny `ui` and `server` code, and put in external package functions ? Some `ui/server` code does grow with more complex use cases so documenting would be nice – steveb Jun 25 '17 at 04:00
  • @steveb exactly I mean that you put all the code in the package. after all this what is done by shiny packages. So you can have a server/ui/controls file sin your packages that contain all the logic. In the shiny side , use the repo structure views/servers that contain the ui/server call of each page/view. – agstudy Jun 25 '17 at 04:03
  • @agstudy I think I understand. You create a package and put the `server.R` and `ui.R` files in the `.../R/` and / or `inst` directories. – steveb Jun 25 '17 at 04:10
  • @agstudy I think the answer in the following [SO post](https://stackoverflow.com/questions/37830819/developing-shiny-app-as-a-package-and-deploying-it-to-shiny-server) essentially says what you are suggesting. – steveb Jun 25 '17 at 04:15
  • @steveb I think my answer is steps beyond that. – agstudy Jun 25 '17 at 04:17
  • @agstudy I am a bit new to R packages so I may not completely understand. Do you know of a simple example that captures what you are saying (i.e. a link)? if this is a lot of work than no worries, I will work on figuring it out. I was thinking the ui/server/global would go into the `instr` directory of the package. – steveb Jun 25 '17 at 04:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/147537/discussion-between-agstudy-and-steveb). – agstudy Jun 25 '17 at 04:28

2 Answers2

1

It is a great question. How do you create a complex clear web application with Shiny?I believe that organize a huge project is the weakness of Shiny architecture.

First, Shiny creates a web in only one html document. This document is divided in layers, to develop a huge application you need to manage correctly the layers. However, this thing presents a significant problem, how do you organize the code?

Well, here, there are different ways to do that. Indeed you can apply different methods like Joe Cheng:

In my case, in a huge project I implemented the MVC pattern but adapting it to the Shiny architecture.

agstudy
  • 119,832
  • 17
  • 199
  • 261
Braisly
  • 385
  • 3
  • 13
1

update

Add an example of shiny application


There is not an ideal solution but this is basically what I am doing to deal with my shiny applications to create a robust and well "documented" shiny application:

  • Create a package where you put all your logic within it. Don't worry to call input/output structure from the package as an argument. Also try to create some controls within your package. For example you can have an inline version of some basic shiny controls.

A typical package will have this structure:

 R
     ui-view1.R
     ui-view2.R
     server-server1.R
     server-server2.R
     controls.R
  • Create a shiny application that is structured in a way that reflects your different applications elements. Basically create a view/server files for each app page. You can of course put the shiny application under inst/ui or put it in a separate project.

Here an example:

 app 
     ui.R
     server.R
     global.R
     views
        view1.R
        view2.R
     servers
        server1.R
        server2.R
     init 
        global1.R
        gloabl2.R
agstudy
  • 119,832
  • 17
  • 199
  • 261