我从Rstudio和ShinyApp开始,我有一些问题,这是因为我制作了这个代码,起初工作非常简单但是当我尝试部署我的应用程序时,我的条形图显示我的NA值,我有一些想法,但正如我之前所说,我是非常新的,我想知道你是否可以帮助我。 这是我的代码:
library(shiny)
library(DT)
library(dplyr)
library(ggplot2)
library(reshape2)
library(lubridate)
library(readr)
library(plotly)
library(shiny)
Sys.setlocale('LC_ALL','C')
santander<-read.csv("./Data/Panel modelo liderazgo-Base carga oficial.csv",header=TRUE,sep=";",encoding = "UTF-8",stringsAsFactors=FALSE, na.strings=c("","NA"))
cuestionario<-read.csv("./Data/Panel modelo liderazgo-Base cuestionarios respondidos-30052017.csv",header=TRUE,sep=";",encoding = "UTF-8",na.strings = c("","NA"),stringsAsFactors=FALSE)
shinyServer(function(input,output){
#Filter for person that i will show his stats
bar<-reactive({ data.frame(filter(santander,NOMBRE==input$Nombre))})
herramienta <-reactive({as.list(unique(c(bar()$Nombre_apfut,bar()$Nombre_Hacercosassuc,bar()$Nombre_CrearCult,bar()$Nombre_vocserv)))})
prompers <-reactive({as.list(unique(c(bar()$Prom_tot_apfut,bar()$Prom_tot_Hacercosassuc,bar()$Prom_tot_CrearCult,bar()$Prom_tot_vocserv)))})
eva_persona<-reactive({do.call(rbind, Map(data.frame, herr=herramienta(), perso=prompers()))})
df.m <- reactive({melt(eva_persona(), id.var=c("herr"))})
#Ranking person
promtotal<-reactive({as.list(unique(c(bar()$Prom_tot)))})
ranking<-reactive({as.list(unique(c(bar()$RANKING)))})
tabla1<-reactive({do.call(rbind, Map(data.frame, "Nota Global"=promtotal(), Ranking=ranking()))})
#information about person (Nombre=Name)
resp<-reactive({data.frame(filter(cuestionario,cuestionario$NOMBRE==input$Nombre))})
#Information chart "apoyando el futuro"
encabezado<-reactive({as.list(unique(c(bar()$Nombre_Prom_asc_apfut,bar()$Nombre_Prom_eng_apfut,bar()$Nombre_Prom_gptw_apfut)))})
nota1<-reactive({as.list(unique(c(bar()$Prom_asc_apfut,bar()$Prom_eng_apfut,bar()$Prom_gptw_apfut)))})
apo_fut<-reactive({do.call(rbind, Map(data.frame, encabezado=encabezado(), nota1=nota1()))})
grafo <- reactive({melt(apo_fut(), id.var=c("encabezado"))})
#Information chart "hacer que las cosas sucedan"
nota2<-reactive({as.list(unique(c(bar()$Prom_asc_Hacercosassuc,bar()$Prom_eng_Hacercosassuc,bar()$Prom_gptw_CrearCult)))})
cosas<-reactive({do.call(rbind, Map(data.frame, encabezado=encabezado(), nota2=nota2()))})
grafo2 <- reactive({melt(cosas(), id.var=c("encabezado"))})
#Information chart "Crear Cultura"
nota3<-reactive({as.list(unique(c(bar()$Prom_asc_CrearCult,bar()$Prom_eng_CrearCult,bar()$Prom_gptw_Hacercosassuc)))})
crear<-reactive({do.call(rbind, Map(data.frame, encabezado=encabezado(), nota3=nota3()))})
grafo3 <- reactive({melt(cosas(), id.var=c("encabezado"))})
#Information chart "Vocacion de servicio"
nota4<-reactive({as.list(unique(c(bar()$Prom_asc_vocserv,bar()$Prom_eng_vocserv,bar()$Prom_gptw_vocserv)))})
voca<-reactive({do.call(rbind, Map(data.frame, encabezado=encabezado(), nota4=nota4()))})
grafo4 <- reactive({melt(voca(), id.var=c("encabezado"))})
# Chart "dimension modelo"
c4=c("Apoyando futuro","Hacer que las cosas sucedan","Crear Cultura","Vocacion de servicio")
p<-reactive({ggplot(df.m(),aes(x="Dimensiones del Modelo",y="",title = "Evaluacion dimensiones")) +
geom_bar(aes(x = herr, y = value, fill = c4),
stat="identity", position = "dodge", width = 0.5) +
geom_text(aes(y=value, x=herr,label=value), vjust=1.6, hjust = 0.5,position=position_dodge(width=0.9),
color="black", size=3.5)+
scale_fill_manual("\n", values = c("Apoyando futuro"="chartreuse3","Hacer que las cosas sucedan"="mediumorchid3","Crear Cultura"="deepskyblue2","Vocacion de servicio"="gold"),
labels = c(" Persona", " Banco Santander")) +
labs(x="Dimensiones del Modelo",y="",title = "Evaluacion dimensiones") +
theme_minimal()+ theme(legend.position="none")+ theme(axis.title = element_text(size=14, face="bold"),
axis.text = element_text(size=10),
strip.text.y = element_text(size=12))
})
#Chart "apoyando el futuro"
c1=c("Ascendente","Engagement","Great Place to Work")
a<-reactive({ggplot(grafo(),aes(x="",y="",title = "Apoyando el Futuro")) +
geom_bar(aes(x = encabezado, y = value, fill = c1), stat="identity", position = "dodge", width = 0.5) +
geom_text(aes(y=value, x=encabezado,label=value), vjust=1.6, hjust = 0.5,position=position_dodge(width=0.9),
color="black", size=3.5)+
scale_fill_manual( values = c("Ascendente"="chartreuse4","Engagement"="chartreuse3","Great Place to Work"="chartreuse2") ) +
labs(x="",y="",title = ("Apoyando el Futuro")) +
theme_minimal()+ theme(legend.position="none")+ theme(axis.title = element_text(size=14, face="bold"),
axis.text = element_text(size=10, face="bold"),
strip.text.y = element_text(size=12, face="bold"))
})
#Chart "hacer que las cosas sucedan"
c2=c("Ascendente","Engagement","Great Place to Work")
b<-reactive({ggplot(grafo2(),aes(x="",y="",title = "Hacer que las cosas Sucedan")) +
geom_bar(aes(x = encabezado, y = value, fill = c2),
stat="identity", position = "dodge", width = 0.5) +
geom_text(aes(y=value, x=encabezado,label=value), vjust=1.6, hjust = 0.5,position=position_dodge(width=0.9),
color="black", size=3.5)+
scale_fill_manual("/n", values = c("Ascendente"="mediumorchid4","Engagement"="mediumorchid3","Great Place to Work"="mediumorchid1"),
labels = c("Persona")) +
labs(x="",y="",title = ("Hacer que las cosas Sucedan")) +
theme_minimal()+ theme(legend.position="none")+ theme(axis.title = element_text(size=14, face="bold"),
axis.text = element_text(size=10, face="bold"),
strip.text.y = element_text(size=12, face="bold"))
})
#Chart "crear cultura"
c5=c("Ascendente","Engagement","Great Place to Work")
d<-reactive({ggplot(grafo3(),aes(x="",y="",title = "Crear Cultura")) +
geom_bar(aes(x = encabezado, y = value, fill = c5),
stat="identity", position = "dodge", width = 0.5) +
geom_text(aes(y=value, x=encabezado,label=value), vjust=1.6, hjust = 0.5,position=position_dodge(width=0.9),
color="black", size=3.5)+
scale_fill_manual("/n", values = c("Ascendente"="deepskyblue4","Engagement"="deepskyblue3","Great Place to Work"="deepskyblue"),
labels = c("Persona")) +
labs(x="",y="",title = ("Crear Cultura")) +
theme_minimal()+ theme(legend.position="none")+ theme(axis.title = element_text(size=14, face="bold"),
axis.text = element_text(size=10, face="bold"),
strip.text.y = element_text(size=12, face="bold"))
})
#Chart "vocacion de servicio"
c3=c("Ascendente","Engagement","Great Place to Work")
v<-reactive({ggplot(grafo4(),aes(x="",y="",title = "Vocación de Servicio")) +
geom_bar(aes(x = encabezado, y = value, fill = c3),
stat="identity", position = "dodge", width = 0.5) +
geom_text(aes(y=value, x=encabezado,label=value), vjust=1.6, hjust = 0.5,position=position_dodge(width=0.9),
color="black", size=3.5)+
scale_fill_manual("/n", values = c("Ascendente"="gold4","Engagement"="gold3","Great Place to Work"="gold1"),
labels = c(" Persona", "")) +
labs(x="",y="",title = ("Vocación de Servicio")) +
theme_minimal()+ theme(legend.position="none")+ theme(axis.title = element_text(size=14, face="bold"),
axis.text = element_text(size=10, face="bold"),
strip.text.y = element_text(size=12, face="bold"))
})
#OUTPUTS UI
output$seg6<-renderUI({
selectInput("division","Elija División",c("Todos",santander$Division_UR))
})
output$seg2<-renderUI({
selectInput("piramide","Seleccione Jefatura",c("Todos",santander$Piramide[santander$Division_UR==input$division]),selected=NULL
,multiple=FALSE)
})
output$seg3<-renderUI({
selectInput("area","Seleccione Área:",c("Todos",santander$area_UR[santander$Piramide==input$piramide &
santander$Division_UR==input$division]),selected=NULL
,multiple=FALSE)
})
output$seg4<-renderUI({
selectInput("gerencia","Seleccione Gerencia:",c("Todos",santander$Gerencia_UR[santander$Piramide==input$piramide &
santander$Division_UR==input$division &
santander$area_UR==input$area]),selected=NULL
,multiple=FALSE)
})
output$seg5<-renderUI({
selectInput("Nombre","Seleccione Líder:",c(santander$NOMBRE[santander$Piramide==input$piramide &
santander$Division_UR==input$division &
santander$area_UR==input$area &
santander$Gerencia_UR==input$gerencia]),selected=NULL
,multiple=FALSE)
})
output$graf1<-renderPlot({
p()
})
output$tabla1<-renderTable({
tabla1()
})
output$tabla2<-renderTable({
resp()
},aoColumnDefs = list(list(sWidth=c("Nombre"), aTargets=list(0))))
output$graf2<-renderPlot({
a()
})
output$graf3<-renderPlot({
b()
})
output$graf4<-renderPlot({
d()
})
output$graf5<-renderPlot({
v()
})
}
)
而且ui.R是:
santander<-read.csv("./Data/Panel modelo liderazgo-Base carga oficial.csv",header=TRUE,sep=";",encoding ="LATIN1",na.strings = c("","NA"),stringsAsFactors=FALSE)
cuestionario<-read.csv("./Data/Panel modelo liderazgo-Base cuestionarios respondidos-30052017.csv",header=TRUE,sep=";",encoding = "LATIN1",na.strings = c("","NA"),stringsAsFactors=FALSE)
shinyUI(
fluidPage(
br(),
fixedRow(
column(6,div(img(src="SantanderRed.png", height=60,width=260))),
column(3, offset=3,div(img(src="8534538-0-img-logo-responsive.png",height=60,width=240 )),alrig="left")
) ,
br(),
br(),
fluidRow(
column(12,titlePanel(title=strong("Ficha de resultados por Líder")))),
br(),
sidebarPanel( fluidRow(
column(6,uiOutput("seg6"),
uiOutput("seg2"),
uiOutput("seg3"),
uiOutput("seg4")),
column(6,uiOutput("seg5"))),width=170),
titlePanel(strong("Nota Global Líder")),
br(),
fluidRow( column(6, tableOutput("tabla1"))),
br(),
fluidRow ( column(6,tableOutput("tabla2")) ),
br(),
titlePanel(strong("Evaluación Dimensiones del Modelo")),
plotOutput("graf1"),
br(),
titlePanel(strong(h2("Evaluación por Instrumento"))),
br(),
fluidRow( column(3,plotOutput("graf2")),
column(3,plotOutput("graf3")),
column(3,plotOutput("graf4")),
column(3,plotOutput("graf5"))
)
)
)
谈论数据时,我无法发布这个数据,但如果过滤了这个数据,那么我们就会创建&#34; bar&#34;,&#34; bar&#34;看起来像这样:
bar2<-data.frame(UR =c("3808"),
NOMBRE =c("LORENA PAZ FUENTES GONZALEZ"),
Piramide =c("JEFATURAS"),
Division_UR =c("DIVISION BANCA COMERCIAL"),
Gerencia_UR =c("RED BANCO"),
area_UR =c("TERRITORIAL OCTAVA"),
Prom_tot =c("1,6"),
RANKING =c("1"),
Nombre_apfut =c("Apoyando futuro"),
Prom_tot_apfut =c("1,5"),
Prom_banco_apfut =c("-0,014"),
Nombre_Hacercosassuc =c("Hacer que las cosas sucedan"),
Prom_tot_Hacercosassuc =c("1,6"),
Prom_banco_Hacercosassuc =c("-0,0133"),
Nombre_CrearCult =c("Crear Cultura"),
Prom_tot_CrearCult =c("1,5"),
Prom_banco_CrearCult =c("-0,0108"),
Nombre_vocserv =c("Vocacion de servicio"),
Prom_tot_vocserv =c("1,7"),
Prom_banco_vocserv =c("-0,0055"),
Nombre_Prom_asc_apfut =c("Ascendente"),
Prom_asc_apfut =c("1,9"),
Nombre_Prom_eng_apfut =c("Engagement"),
Prom_eng_apfut =c("1"),
Nombre_Prom_gptw_apfut =c("Great Place to Work"),
Prom_gptw_apfut =c(""),
Nombre_Prom_asc_Hacercosassuc =c("Ascendente"),
Prom_asc_Hacercosassuc =c("2,1"),
Nombre_Prom_eng_Hacercosassuc =c("Engagement"),
Prom_eng_Hacercosassuc =c("1,1"),
Nombre_Prom_gptw_Hacercosassuc =c("Great Place to Work"),
Prom_gptw_Hacercosassuc =c(""),
Nombre_Prom_asc_CrearCult =c("Ascendente"),
Prom_asc_CrearCult =c("1,8"),
Nombre_Prom_eng_CrearCult =c("Engagement"),
Prom_eng_CrearCult =c("1,1"),
Nombre_Prom_gptw_CrearCult =c("Great Place to Work"),
Prom_gptw_CrearCult =c(""),
Nombre_Prom_asc_vocserv =c("Ascendente"),
Prom_asc_vocserv =c("2"),
Nombre_Prom_eng_vocserv =c("Engagement"),
Prom_eng_vocserv =c("1,3"),
Nombre_Prom_gptw_vocserv =c("Great Place to work"),
Prom_gptw_vocserv =c("")
)
我知道也许是非常困惑和奇怪但实际上有效,我只需要我的条形图不要采用NA值。 My ggplot with NA Values