Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- library(tidyverse)
- library(shinydashboard)
- data("mtcars")
- source_data <- mtcars %>% as_tibble() %>% rownames_to_column(var = "model")
- ui <- dashboardPage(
- dashboardHeader(title = "Hello Shiny!"),
- dashboardSidebar(
- checkboxGroupInput("liczba_cylindrow",
- label = "Liczba cylindrów",
- choices = setNames(unique(source_data$cyl), unique(source_data$cyl))
- )
- ),
- dashboardBody(
- fluidRow(
- box(width = 12,
- title = "Moc samochodów",
- plotOutput("wykres_moc"))
- )
- )
- )
- server <- function(input, output) {
- reactive_data <- reactive({
- req(length(input$liczba_cylindrow) > 0) # jeśli nic nie zaznaczono, to nie wykonuj
- data <-
- source_data %>%
- filter(cyl %in% input$liczba_cylindrow)
- return(data)
- })
- output$wykres_moc <- renderPlot({
- reactive_data() %>%
- ggplot(aes(x = hp)) + geom_histogram()
- })
- }
- shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement