renderTable Caption problems

1,053 views
Skip to first unread message

Chetan Mishra

unread,
Mar 10, 2015, 12:12:37 AM3/10/15
to shiny-...@googlegroups.com
I was attempting to add captions to an html table created via renderTable.  While renderTable didn't have a caption argument, I saw that it passed additional arguments to xtable (which did have a caption argument). 

I attempted to use this and received a partial matching error. While there aren't other arguments in xtable starting with "caption", the renderTable() function was also passing the additional arguments to print.xtable (which had arguments caption.placement and caption.width).

I got around this by specifying the values for both caption.placement and caption.width, but is there a way to get around it without having to do that? Is there a better way to add a table title/header within Shiny? A minimal code example is below and here:

library(shiny)

serverShouldWork <- function(input, output) {
  output$bTable <- renderTable({iris}, caption=paste("test"),
    caption.placement = getOption("xtable.caption.placement", "top"),
    caption.width = getOption("xtable.caption.width", NULL)
  )
}

serverDoesWork <- function(input, output) {
  output$bTable <- renderTable({iris}, caption="test")
}

ui <- fluidPage("RenderTable Example",
  tableOutput("bTable") #table of information on beds (beds)
)

app1 <- shinyApp(ui, serverDoesWork)
app2 <- shinyApp(ui, serverShouldWork)

runApp(app1)
runApp(app2)



I apologize if there is something obvious that I've overlooked, I've learned R an isolated, need-to-do manner (so don't know many simple things), and this is my first real development experience with Shiny. 

Yihui Xie

unread,
Mar 10, 2015, 8:07:32 AM3/10/15
to Chetan Mishra, shiny-discuss
I believe that is a bug of shiny. We passed ... to two functions:
https://github.com/rstudio/shiny/blob/4599a7ab4/R/shinywrappers.R#L324-L329
It will be nice if you can file a bug report to
https://github.com/rstudio/shiny/issues Thanks!

Regards,
Yihui

Chetan Mishra

unread,
Mar 10, 2015, 3:12:05 PM3/10/15
to shiny-...@googlegroups.com, cheta...@gmail.com
Submitted.
Reply all
Reply to author
Forward
0 new messages