[Bioc-devel] Guidelines for shiny packages

Shawn Balcome balc0022 at umn.edu
Tue Sep 30 21:21:23 CEST 2014


Hi Thomas,

One possible solution is the example below that conforms to the format
Laurent suggested to you.  Another variation on it is to read the html from
a file in /inst/ and assign it to a character variable:

  myhtml <- readLines("/path/to/index.html")
  app <- list(
    ui = HTML(myhtml),
    ...etc. etc.


Best,

Shawn

-----------------------------------------------------

myapp <- function(object) {
  app <- list(
    ui = HTML("
<html>
<head>
<script src='shared/jquery.js' type='text/javascript'></script>
<script src='shared/shiny.js' type='text/javascript'></script>
<link rel='stylesheet' type='text/css' href='shared/shiny.css'/>
</head>

<body>
<h1>HTML UI</h1>

<p>
<label>Distribution type:</label><br />
<select name='dist'>
<option value='norm'>Normal</option>
<option value='unif'>Uniform</option>
<option value='lnorm'>Log-normal</option>
<option value='exp'>Exponential</option>
</select>
</p>

<p>
<label>Number of observations:</label><br />
<input type='number' name='n' value='500' min='1' max='1000' />
</p>

<pre id='summary' class='shiny-text-output'></pre>

<div id='plot' class='shiny-plot-output'
style='width: 100%; height: 400px'></div>

<div id='table' class='shiny-html-output'></div>
</body>

</html>
              "),
    server = function(input, output) {

      data <- reactive({
        dist <- switch(input$dist,
                       norm = rnorm,
                       unif = runif,
                       lnorm = rlnorm,
                       exp = rexp,
                       rnorm)

        dist(input$n)
      })

      output$plot <- renderPlot({
        dist <- input$dist
        n <- input$n

        hist(data(),
             main=paste('r', dist, '(', n, ')', sep=''))
      })

      output$summary <- renderPrint({
        summary(data())
      })

      output$table <- renderTable({
        data.frame(x=data())
      })
    }
  )
  runApp(app)
}

-----------------------------------------------------

On Mon, Sep 29, 2014 at 3:11 PM, Thomas Dybdal Pedersen <thomasp85 at gmail.com
> wrote:

> Unfortunately this approach is limited to apps where the UI of the app is
> defined in R code. For more involved GUI development it is much preferred
> to write the HTML yourself and for this to work, there need to be a
> server.R file. I don’t think we should have recommendations that limits the
> developer to such an extend…
>
> best
>
> Thomas
>
>
> On 29 Sep 2014, at 21:59, Laurent Gatto <lg390 at cam.ac.uk> wrote:
>
> >
> > On 29 September 2014 20:49, Thomas Dybdal Pedersen wrote:
> >
> > Dear Thomas,
> >
> >> Hi All
> >>
> >> I’m in the process of getting package submitted to Bioconductor. The
> >> package is a pure shiny package and this has led to some - especially
> >> one question. For those not familiar with shiny apps, the code that
> >> makes these work resides in their own .R files outside of the R
> >> directory in a package. Consequently they are not ‘build’ and whatever
> >> is in there is not part of the package namespace. The functionality of
> >> my GUI requires several packages, but for the reasons given above they
> >> are not imported into the package namespace. Still they are needed for
> >> the package to function properly. The main question is thus: How to
> >> state this hard dependency in the DESCRIPTION file without getting
> >> knocked on the head for not importing your dependencies during check
> >> and BiocCheck?
> >
> > When developing a package, I do not use the server.R and ui.R files, but
> > define the shiny app in R/code.R as follow.
> >
> >  myapp <- function(object) {
> >    app <- list(
> >      ui = bootstrapPage( ... ),
> >      server = function(input, output) { ... }
> >    )
> >  }
> >
> > and dependencies are stated in DESCRIPTION and NAMESPACE.
> >
> > Hope this helps.
> >
> > Laurent
> >
> >> Another related question/proposal is: Based on the interest in Shiny
> >> at BioC 2014 it seems as we should anticipate a lot of shiny based
> >> packages. As one of the core principles of the Bioconductor project is
> >> to promote good coding style and high quality packages I was wondering
> >> whether it would make sense to begin working on a set of guidelines
> >> for developing shiny based GUIs, as their structure and style differs
> >> a lot from standard R packages. Just a suggestion - I’ll happily join
> >> such an effort…
> >>
> >> best
> >>
> >> Thomas
> >> _______________________________________________
> >> Bioc-devel at r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/bioc-devel
> >
> >
> > --
> > Laurent Gatto
> > http://cpu.sysbiol.cam.ac.uk/
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>

	[[alternative HTML version deleted]]



More information about the Bioc-devel mailing list