Document a shiny application
Asked Answered
V

2

11

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.

Viscera answered 8/7, 2015 at 22:33 Comment(12)
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.Herbage
@Herbage 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?Viscera
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.Altazimuth
@Viscera Did you ever find a solution to this that you were looking for ?Reeding
@Reeding create a package and put all functions within it. function can have input , output as parameters.Viscera
@Viscera 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 niceReeding
@Reeding 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.Viscera
@Viscera I think I understand. You create a package and put the server.R and ui.R files in the .../R/ and / or inst directories.Reeding
@Viscera I think the answer in the following SO post essentially says what you are suggesting.Reeding
@Reeding I think my answer is steps beyond that.Viscera
@Viscera 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.Reeding
Let us continue this discussion in chat.Viscera
V
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
Viscera answered 25/6, 2017 at 4:14 Comment(0)
D
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.

Daughtry answered 9/8, 2015 at 9:57 Comment(0)
V
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
Viscera answered 25/6, 2017 at 4:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.