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