Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document a shiny application

Tags:

r

roxygen2

shiny

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.

like image 411
agstudy Avatar asked Jul 08 '15 22:07

agstudy


People also ask

What is a Shiny document?

Shiny is an R package that makes it easy to build interactive web apps straight from R. You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.

How do you structure a Shiny app?

A Shiny app consists of two parts, a user interface ( ui ) and an R session that runs code and returns results ( server ). These two parts can be in their own files called ui. R and server.

What is a Shiny application?

Shiny is an R package that enables building interactive web applications that can execute R code on the backend. With Shiny, you can host standalone applications on a webpage, embed interactive charts in R Markdown documents, or build dashboards.


2 Answers

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:

  • https://github.com/jcheng5/shiny-partials

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

like image 130
Braisly Avatar answered Sep 20 '22 23:09

Braisly


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
like image 24
agstudy Avatar answered Sep 21 '22 23:09

agstudy