1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
| #
# 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("shinyWidgets")
library(shinydashboard)
library(shinythemes)
library(shiny)
library(readr)
data <- read_csv("C:/Users/Marie-Noelle/OneDrive/Desktop/L3-G1 DU Actuariat/projet R/S2/BDD/master - Copie.csv")
data$country<-as.factor(data$country)
data$sex<-as.factor(data$sex)
data$age<-as.factor(data$age)
data$generation<-as.factor(data$generation)
data$`country-year`<-as.factor(data$`country-year`)
# Define UI for application that draws a histogram
header = dashboardHeader(title = "Taux de suicide entre 1985 et 2016", titleWidth = 450)
sidebar = dashboardSidebar(
sidebarMenu(
menuItem("Accueil", tabName = "accueil", icon = icon("home")),
menuItem("Analyse univariee", icon = icon("th"), tabName = "uni"),
menuItem("Analyse bivariee", icon = icon("signal"), tabName = "biv"),
menuItem("Tests", icon = icon("flag"), tabName = "test"),
menuItem("Cartes",icon = icon("globe"), tabName = "cartes")
)
)
body = dashboardBody(
tabItems(
##################### Accueil ###################################
tabItem(tabName = "accueil",
fluidRow(
box(
title = "More info", background = "olive", width = 4, collapsible = TRUE,
uiOutput("listMovies")),
box(
title = "More info", background = "red", width = 4, collapsible = TRUE,
uiOutput("listMovies")),
box(
title = "More info", background = "purple", width = 4, collapsible = TRUE,
uiOutput("listMovies"))
),
fluidRow(
box(
title = "Table", status = "success", width = 8, solidHeader = TRUE,
DT::dataTableOutput("moviePicker")
)),
tags$h3("Evolution du nombre de suicides en fonction du temps"),
br(),
dropdownButton(
tags$h3("Selectionnez des parametres"),
selectInput(inputId = 'type',
label = 'Type de graphe',
choices = c("Courbe","lineaire", "camember")),
selectInput(inputId = 'col',
label = 'Choisissez une couleur',
choices = c("red","blue","yellow"),
selected = 1),
sliderInput(inputId = 'annee', "Year", min = 1958, max = 2016,
value = c(1958, 2016), sep = ""),
circle = TRUE, status = "danger",
icon = icon("gear"), width = "300px",
tooltip = tooltipOptions(title = "Click to see inputs !")
),
plotOutput(outputId = 'plot1')
)
,
#############################################################
tabItem(tabName = "cartes",
h2("Dashboard tab content")),
tabItem(tabName = "uni",
h2("Analyse Univariee"),
fluidRow(
tabBox(width = 5, title = "Graphs",
tabPanel("LOESS", plotOutput("budgetYear")),
tabPanel("Linear", plotOutput("budgetYearLinear"))
),
box(
title = "Annees", width = 4,
sliderInput("year", "Year", min = 1958, max = 2016,
value = c(1958, 2016), sep = "")
),
box(
width = 3, status = "info",
checkboxGroupInput("checkbox", "Choose your...",
choices = c("Own adventure",
"Weapon",
"Next words wisely"))
)
)
),
tabItem(tabName = "biv",
h2("Analyse Bivariee"),
fluidRow(
tabBox(width = 5, title = "Graphs",
tabPanel("LOESS", plotOutput("budgetYear")),
tabPanel("Linear", plotOutput("budgetYearLinear"))
),
box(
title = "Annees", width = 4,
sliderInput("year", "Year", min = 1958, max = 2016,
value = c(1958, 2016), sep = "")
),
box(
width = 3, status = "info",
checkboxGroupInput("checkbox", "Choose your...",
choices = c("Own adventure",
"Weapon",
"Next words wisely"))
)
)
),
tabItem(tabName = "test",
h2("Tests"),
fluidRow(
tabBox(width = 5, title = "Graphs",
tabPanel("LOESS", plotOutput("budgetYear")),
tabPanel("Linear", plotOutput("budgetYearLinear"))
),
box(
title = "Annees", width = 4,
sliderInput("year", "Year", min = 1958, max = 2016,
value = c(1958, 2016), sep = "")
),
box(
width = 3, status = "info",
checkboxGroupInput("checkbox", "Choose your...",
choices = c("Own adventure",
"Weapon",
"Next words wisely"))
)
)
)
))
ui<-dashboardPage(header, sidebar, body,skin="black")
# Define server logic required to draw a histogram
server <- function(input, output,session) {
data_chemin<-paste("C:/Users/Marie-Noelle/OneDrive/Desktop/L3-G1 DU Actuariat",
"projet R/S2/BDD/master - Copie.csv",
sep="/")
data <- read_csv(data_chemin)
debut <- reactive({ as.integer(input$annee[1]) })
fin <- reactive({as.integer(input$annee[2])})
selected <- reactive({
data%>% filter(year%in% seq(2000, 2016))%>%
aggregate(`suicides/100k pop`, list(year), sum )%>%
colnames()=c("year","nb_suicides")
})
moyenne_suicides <- mean(selected())
output$plot1<- renderPlot({
par(mar = c(5.1, 4.1, 0, 1))
ggplot(selected(), aes(y=nb_suicides, x=year, col=input$col)) +
geom_point(size=2, pch=17, col="red")+
scale_x_continuous(breaks = seq(debut(), fin(), 2)) +
geom_hline(yintercept=moyenne_suicides, linetype = 2,
color = "red", size = 1) +
labs(title = "Suicides globale par 100000 habitants",
subtitle = "Tendance entre 1985 et 2015.",
x = "Year",
y = "Suicides par 100k")
})
}
# Run the application
shinyApp(ui = ui, server = server) |
Partager