Skip to content

Instantly share code, notes, and snippets.

@LilianaPacheco
Created May 23, 2015 18:48
Show Gist options
  • Save LilianaPacheco/f8b271a82d6fbb94d3ee to your computer and use it in GitHub Desktop.
Save LilianaPacheco/f8b271a82d6fbb94d3ee to your computer and use it in GitHub Desktop.
Codes for the coursera project
library(shiny)
source("grafico.R")
source("tablas.R")
source("chicuadrado.R")
source("modelo.R")
source("grafico_logistico.R")
library(shinythemes)
datos = read.csv2("Base inicial.csv",header=T,sep=";",enc="latin1")
# Define server logic for random distribution application
shinyServer(function(input, output) {
output$contents <- renderDataTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=T, sep=";")
})
output$data_table<-renderDataTable({
# inFile <- input$file1
filas<-input$num
# if (is.null(inFile))
# return(NULL)
# mydat<-read.csv(inFile$datapath, header=T, sep=";")
mydat<-datos
head(mydat,filas)
})
# Reactive expression to generate the requested distribution.
# This is called whenever the inputs change. The output
# functions defined below then all use the value computed from
# this expression
data <- reactive({
variable <- switch(input$variable,
norm = rnorm,
unif = runif,
lnorm = rlnorm,
exp = rexp,
rnorm
)
variable(input$n) #recordemos que cada rdist(necesita tamaño)
})
# Generate a plot of the data. Also uses the inputs to build
# the plot label. Note that the dependencies on both the inputs
# and the data reactive expression are both tracked, and
# all expressions are called in the sequence implied by the
# dependency graph
output$plot <- renderPlot({
variable <- input$variable
n <- input$n
hist(data(),
main=paste('r', variable, '(', n, ')', sep=''))
})
# Generate a summary of the data
output$summary <- renderPrint({
summary(data())
})
#
selectedData <- reactive({
inFile <- input$file1
#mydat<-read.csv(inFile$datapath, header=T, sep=";")
mydat<-datos
mydat[,input$socio]
})
#Salidas tabulares de la función
output$tabla <- renderTable({
#inFile <- input$file1
mydat<-datos
sentido<-input$select
var2<-"Retirement"
#mydat<-read.csv(inFile$datapath, header=T, sep=";")
tablas(mydat,input$socio,var2, sentido)
})
#Generar los gráficos apilados
output$apilado <- renderPlot({
#inFile <- input$file1
sentido<-input$select
#mydat<-read.csv(inFile$datapath, header=T, sep=";")
mydat<-datos
#grafico(selectedData(),mydat$Retirado, sentido)
var2<-"Retirement"
#mydat<-read.csv(inFile$datapath, header=T, sep=";")
grafico(mydat,input$socio,var2, sentido)
})
#Generar tabla chicuadrado
output$chicuad <- renderPrint({
sentido<-input$select
mydat<-datos
var2<-"Retirement"
chic(mydat,input$socio,var2, sentido)
})
#Generar modelo logóstico
output$modelo <- renderPrint({
mydat<-datos
var2<-"Retirement"
modelo(mydat,input$regresora,var2)
})
#Generar grafico logóstico
output$graficoModelo <- renderPlot({
mydat<-datos
var2<-"Retirement"
grafico.logistico(mydat,input$regresora,var2)
})
})
library(shiny)
library(shinythemes)
shinyUI(fluidPage(theme = shinytheme("united"),
headerPanel("",tags$head(
tags$img(src="logotipo.png", height="50px", align = "right")
)),
titlePanel("Statistical Influence of Variables in Staff Rotation Analysis - Liliana Pacheco"),
navbarPage("Contents",
tabPanel("Instructions",
sidebarLayout(
sidebarPanel(
helpText("The purpose of this application is to show from a series of demographic variables,",
"which of them may have a statistical influence on the event of Retiring or Not",
"retiring from a specific company.")
),
mainPanel(
p("Here we have the general instructions for this web application:"),
tags$ol(
tags$li(strong("Data:"),"This panel shows you the dataset and its variables."),
tags$li(strong("Bivariate - Descriptives:"), "This panel shows the Stacked bar graph of a demographic variable for you to choose and the percentage
of employees who have retired from the company.", br("Also, you will see a table showing
the frequencies, row and column percentages. And finally the results of a Chi-square Test.")),
tags$li(strong("Model:"), "This panel shows the logistic model results of the variables you choose and Retirement.")
)
)
)
),
tabPanel("Data",
sidebarLayout(
sidebarPanel(
#Si se desea que cargue el archivo manualmente
# fileInput('file1', 'Seleccionar Archivo',
# accept=c('text/csv',
# 'text/comma-separated-values,text/plain',
# '.csv')),
p("We use the dataset that contains the results of a
survey made with a group of employees from a
company during December. Here we have:",
strong("Demographic variables,"),strong("Performance variables"), "and", strong("Income.")),
numericInput("num", label = h4("How many rows do you want to see first?"), value = 10)
,width=3.5),
mainPanel(
dataTableOutput('data_table')
)
)
),
tabPanel("Bivariate - Descriptives",
sidebarLayout(
sidebarPanel(
radioButtons("socio", "Demographics:",
c("Gender" = "Gender",
#"Programa" = "Programa",
"City" = "City",
"Were you studing when you began working?" = "Studing.when.started",
"Are you currently studing?" = "Currently.studing",
"Level of Education" = "Level.of.education",
"Condition of studies" = "State.of.studies",
"Area of studies" = "Area.of.studies",
"Are you the head of your household?" = "Head.of.household",
"Part of your income is for your household?" = "Part.of.your.income.is.for.household",
"Do you have children?" = "Has.Children",
"Are you satisfied working in this company?" = "Satisfaction"
)),
# Retirement Days of work Months of work Performance Mean Performance Fixed Income Variable Income
br(),
selectInput("select", label = h4("Choose the X axis orientation"),
choices = list("Horizontal" = 1, "Vertical" = 2),
selected = 1)
,width=3),
mainPanel(
plotOutput("apilado"),
tableOutput('tabla'),
verbatimTextOutput("chicuad")
)
)
),
tabPanel("Model",
sidebarLayout(
sidebarPanel(
radioButtons("regresora", "Choose a variable for the logistic model:",
c("Age" = "Age",
"Days working" = "Days.of.work",
"Months working" = "Months.of.work",
"Mean Performance" = "Mean.Performance",
"Fixed Income" = "Fixed.Income",
"Variable Income" = "Variable.Income",
"Mean Adhesion" = "Mean.Adhesion",
"Mean Ratio Connections/Shift" = "Mean.Ratio.Connections.Shift",
"Mean AHT" = "Mean.AHT"))
),
mainPanel(
plotOutput("graficoModelo"),
#verbatimTextOutput("graficoModelo"),
verbatimTextOutput("modelo")
)
)
)
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment