-
-
Save dmurdoch/11f494b55fa8544c53e26f96033d08e6 to your computer and use it in GitHub Desktop.
Use kable in Shiny
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- fluidPage( | |
# Application title | |
titlePanel("mtcars"), | |
sidebarLayout( | |
sidebarPanel( | |
sliderInput("mpg", "mpg Limit", | |
min = 11, max = 33, value = 20) | |
), | |
mainPanel( | |
tableOutput("mtcars_kable") | |
) | |
) | |
) | |
server <- function(input, output) { | |
library(dplyr) | |
library(kableExtra) | |
output$mtcars_kable <- function() { | |
req(input$mpg) | |
mtcars %>% | |
mutate(car = rownames(.)) %>% | |
tibble::remove_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)) | |
} | |
} | |
# Run the application | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment