4

Is there a way to use a render__ function to render a Kable (knitr::) with Shiny in Flexdashboard? I am finding information about general Shiny-Kable rendering, but not specifically with Flexdashboard. Links like this one are helpful but it would be great to be able to call a render_ function to display the Shiny interactive Kable in my Flexdashboard. Any advice would be awesome!

Thanks!

Stefan

IVIM
  • 2,167
  • 1
  • 15
  • 41

3 Answers3

3

the following is one way of getting this to work in flexdashboard.

your_reactive_data <- reactive({ your_data })

shiny::renderUI(
    HTML(
        kable(your_reactive_data())
    )
)
Community
  • 1
  • 1
Engelstad
  • 31
  • 4
  • Did not work for me, even with `{r results='asis'}`, it still prints just ASCII `|date |country |city |state | ||:----------|:-------|:----------|:-- ....` instead of nice table – IVIM May 03 '20 at 02:48
0

The above answer did not work (for me). However what worked is using xtable::xtable() instead of kable(). They are produce similar output, and it has the corresponding renderTable() function. (as opposed to kable that does not have (yet) a corresponding renderKable() function.

renderTable({
  your_reactive_data() %>% xtable::xtable()
})

IVIM
  • 2,167
  • 1
  • 15
  • 41
0

The correct way to do it (according to this documentation) is just to wrap your code in an empty function:

output$mtcars_kable <- function() {
 req(input$mpg)
 mtcars %>%
   mutate(car = rownames(.)) %>%
   select(car, everything()) %>%
   filter(mpg <= input$mpg) %>%
   knitr::kable("html") %>%
   kable_styling("striped", full_width = F) %>%
   add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6))
}

My guess is that it's because the kable_styling function already generates HTML, you don't need a render*() function.

fahmy
  • 3,543
  • 31
  • 47