title: Show documentation pages in shiny app
body: <p>I have a shiny app where I want to display some documentation pages in the GUI. The following app works well for packages that were installed as source packages, i.e. with </p>
  
  <pre><code>install.packages(packagename, type = "source")
  </code></pre>
  
  <p>However, for binary packages I am not able to extract the same <code>html</code> files from the package directory. Having access to <code>.Rd</code> files would be enough due to <code>tools::Rd2HTML</code>. Any help would be appreciated.</p>
  
  <pre><code>library(shiny)
  
  # get a character vector containing all source packages or packages
  # containing more than two files in pkgdir/html
  pkgs &lt;- rownames(installed.packages())
  ndoc &lt;- vapply(pkgs, function(pkg){
    length(list.files(system.file("html", package = pkg)))}, 0)
  src_pkgs &lt;- pkgs[ndoc &gt; 2]
  
  ui &lt;- fluidPage(
    selectInput("package", "select package", src_pkgs),
    uiOutput("choose_topic"),
    wellPanel(uiOutput("documentation"))
  )
  
  server &lt;- function(input, output, session){
    output$choose_topic &lt;- renderUI({
      choices &lt;- list.files(system.file("html", package = input$package))
      selectInput("topic", "select topic", choices)
    })
  
    output$documentation &lt;- renderUI({
      includeHTML(
        system.file(paste0("html/", req(input$topic)), package = input$package)
      )
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <h2>Edit</h2>
  
  <p>I just came up with an alternative way of showing the man pages using <code>tools::startDynamicHelp</code>. This works with all packages and even enables links to other man pages. However, this approch doesn't work with <code>shiny-server</code> since it uses the loopback interface (<code>127.0.0.1</code>).</p>
  
  <pre><code>library(shiny)
  
  pkgs &lt;- rownames(installed.packages())
  
  ui &lt;- fluidPage(sidebarLayout(
    sidebarPanel(
      selectInput("package", "select package", pkgs),
      uiOutput("choose_topic")
    ),
    mainPanel(uiOutput("documentation"))
  ))
  
  server &lt;- function(input, output, session){
    port &lt;-  tools::startDynamicHelp(NA)
    home &lt;- paste0("http://127.0.0.1:", port)
  
    output$choose_topic &lt;- renderUI({
      choices &lt;- unique(readRDS(system.file("help/aliases.rds", package = input$package)))
      selectInput("topic", "select topic", choices)
    })
  
    output$documentation &lt;- renderUI({
      url &lt;- paste0(home, "/library/", input$package, "/html/", input$topic,".html")
      tags$iframe(src = url, width = "100%", height = "900px")
    })
  }
  
  shinyApp(ui, server, options = list(launch.browser = TRUE))
  </code></pre>