Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. library(shiny)
  2. library(tidyverse)
  3. library(shinydashboard)
  4.  
  5. data("mtcars")
  6. source_data <- mtcars %>% as_tibble() %>% rownames_to_column(var = "model")
  7. ui <- dashboardPage(
  8. dashboardHeader(title = "Hello Shiny!"),
  9. dashboardSidebar(
  10. checkboxGroupInput("liczba_cylindrow",
  11. label = "Liczba cylindrów",
  12. choices = setNames(unique(source_data$cyl), unique(source_data$cyl))
  13. )
  14. ),
  15. dashboardBody(
  16. fluidRow(
  17. box(width = 12,
  18. title = "Moc samochodów",
  19. plotOutput("wykres_moc"))
  20. )
  21. )
  22. )
  23. server <- function(input, output) {
  24. reactive_data <- reactive({
  25. req(length(input$liczba_cylindrow) > 0) # jeśli nic nie zaznaczono, to nie wykonuj
  26. data <-
  27. source_data %>%
  28. filter(cyl %in% input$liczba_cylindrow)
  29. return(data)
  30. })
  31. output$wykres_moc <- renderPlot({
  32. reactive_data() %>%
  33. ggplot(aes(x = hp)) + geom_histogram()
  34. })
  35. }
  36. shinyApp(ui = ui, server = server)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement