blob: 5cfcedbde21710a4136915038ea490cf45e03b1c [file] [log] [blame]
Hao Zhuf9aa4c42017-05-22 15:53:35 -04001---
2title: "Use kable in Shiny"
3output: html_document
Hao Zhu6ce29212017-05-22 16:29:56 -04004vignette: >
5 %\VignetteIndexEntry{Use kable in Shiny}
6 %\VignetteEngine{knitr::rmarkdown}
7 %\VignetteEncoding{UTF-8}
Hao Zhuf9aa4c42017-05-22 15:53:35 -04008---
9
10```{r setup, include=FALSE}
11knitr::opts_chunk$set(echo = TRUE)
12```
13
Hao Zhubd95bb22017-05-22 16:08:49 -040014To use `knitr::kable()` and `kableExtra` in shiny couldn't be simpler.
Hao Zhuf9aa4c42017-05-22 15:53:35 -040015```{r, eval = FALSE}
16library(shiny)
17
18ui <- fluidPage(
19
20 # Application title
21 titlePanel("mtcars"),
22
23 sidebarLayout(
24 sidebarPanel(
25 sliderInput("mpg", "mpg Limit",
26 min = 11, max = 33, value = 20)
27 ),
28
29 mainPanel(
30 tableOutput("mtcars_kable")
31 )
32 )
33)
34
35server <- function(input, output) {
36 library(dplyr)
37 library(kableExtra)
38 output$mtcars_kable <- function() {
39 req(input$mpg)
40 mtcars %>%
41 mutate(car = rownames(.)) %>%
42 select(car, everything()) %>%
43 filter(mpg <= input$mpg) %>%
44 knitr::kable("html") %>%
45 kable_styling("striped", full_width = F) %>%
46 add_header_above(c(" ", "Group 1" = 5, "Group 2" = 6))
47 }
48}
49
50# Run the application
51shinyApp(ui = ui, server = server)
52
53
54```
55
56To simply:
57
58```{r, eval=FALSE}
59shiny::runGist("https://gist.github.com/haozhu233/9e675e1a8a1bb4744f9ebc9246a2366b")
60```