# # This is a Shiny web application. You can run the application by clicking # the 'Run App' button above. # # Find out more about building applications with Shiny here: # # http://shiny.rstudio.com/ # library(shiny) library(RMySQL) library(tidyverse) yhendus<-dbConnect(dbDriver("MySQL"), user="root", password="root", host="localhost", dbname='film') paring<-dbSendQuery(yhendus, "SELECT id, production_year FROM efis_film WHERE LENGTH(production_year)=4") filmiandmed=fetch(paring, n=-1) %>% mutate(production_year=as.numeric(production_year)) dbDisconnect(yhendus) head(filmiandmed) ui <- fluidPage( selectInput("valikSugu", "Vali sugu", c("mees"="a", "naine"="b", "teadmata"="c")), sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30), numericInput(inputId="minAasta", "Algusaasta", 1925), textOutput("tekst1"), dataTableOutput("tabel2"), plotOutput("distPlot"), tableOutput("tabel1") ) server <- function(input, output) { output$tekst1 <- renderText(paste("Pärast aastat ", input$minAasta, " on tehtud ", sum(filmiandmed$production_year>input$minAasta), " filmi ", input$valikSugu)) output$tabel2 <- renderDataTable({ filmiandmed %>% filter(production_year>input$minAasta) %>% arrange(production_year) } ) output$distPlot <- renderPlot({ filmiandmed %>% filter(production_year>input$minAasta) %>% ggplot(aes(production_year)) + geom_histogram(bins=input$bins) }) output$tabel1 <- renderTable({ filmiandmed %>% filter(production_year>input$minAasta) %>% arrange(production_year) %>% head(10) }) } shinyApp(ui = ui, server = server)