Guest User

Untitled

a guest
Dec 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. training <- read.csv("~/Desktop/training.csv")
  2. library(shiny)
  3. library(tidyverse)
  4.  
  5.  
  6.  
  7. # Define UI for application that draws a histogram
  8. ui <- shinyUI(fluidPage(
  9.  
  10.  
  11. titlePanel("Gráficas:"),
  12.  
  13. # Sidebar with a slider input for Variables
  14. sidebarLayout(
  15. sidebarPanel(
  16.  
  17. selectInput(inputId = "y",
  18. label = "y",
  19. choices = "Sales",
  20. selected = "Sales"
  21.  
  22. ),
  23.  
  24. selectInput(inputId = "x",
  25. label = "Variable",
  26. choices = c( "Products Bought" = "ProdBought",
  27. "Numero de casas" = "NumCasas"
  28. ),
  29. selected = "ProdBought")
  30. ),
  31.  
  32.  
  33. # Show a plot of the generated distribution
  34. mainPanel(
  35. plotOutput(outputId = "BarPlot")
  36.  
  37. )
  38. )
  39. ))
  40.  
  41.  
  42. server <- shinyServer(function(input, output) {
  43. # generate plot
  44. output$BarPlot <- renderPlot({
  45.  
  46. training %>%
  47. group_by(input$x, Sales) %>%
  48. count() -> conteos
  49.  
  50. ggplot(data = conteos, aes(x = input$x, y = n, fill = Sales)) +
  51. geom_col()
  52.  
  53. })
  54. })
  55.  
  56. # Run the application
  57. shinyApp(ui = ui, server = server)
Add Comment
Please, Sign In to add comment