Reputation: 719
I'm building a shiny app and I need one of the tabpanels to show the R Documentation of one of the functions of the package RecordLinkage, so the user can choose his argument options.
I have tried
library(shiny)
library(RecordLinkage)
ui <- fluidPage(
tabPanel("Literature of functions",
selectInput(
"literatureChoice",
"Choose a function : ",
choices = c("compare.dedup",
"compare.linkage")
),
textOutput("literatureOutput")
),
)
server <- function(input, output) {
output$literatureOutput <- renderText({
?compare.linkage
})
}
But it doesn't show any documentation. I'm aware that ?compare.linkage shows in help panel in RStudio instead of the console.
Upvotes: 0
Views: 349
Reputation: 2835
R help documentations are stored in Rd
objects. We need a way to fetch this object and render them in Shiny.
We fetch the Rd
object with the help of Rd_fun()
found in the gbRd
package.
We then parse the file into html with Rd2HTML
. The file is saved in the temp directory and read back into R.
The example is for the reactive()
function found in the shiny
package, replace it with whichever function required.
library(shiny)
library(gbRd)
library(tools)
ui <- fluidPage(
tabPanel("Literature of functions",
selectInput(
"literatureChoice",
"Choose a function : ",
choices = c("compare.dedup",
"compare.linkage")
),
htmlOutput("literatureOutput")
)
)
server <- function(input, output) {
output$literatureOutput <- renderText({
temp = Rd2HTML(Rd_fun("reactive"),out = tempfile("docs"))
content = read_file(temp)
file.remove(temp)
content
})
}
shinyApp(ui,server)
Upvotes: 2