#Comienzo la aplicación
#Cargo las libreríasrequire(shiny)require(rsconnect)require(ggplot2)
#Cambio el directorio (solo lo uso si lo voy a correr local)#setwd("C:/Users/borja.sanz/Desktop/Borja/R/Shiny/Directorio - Proyecciones Productos")
#Cargo los datosdata<-read.csv("./data/Pruebas.Shiny.csv")
#Cambio las fechas a formato de fechadata$Fecha = as.POSIXct(data$Fecha, format = "%d/%m/%Y")
#Extraigo el añodata$Año = as.factor(format(data$Fecha, "%Y"))
#Quito comas de los numeros (si hay)data$Unidades = as.numeric(gsub(",","",data$Unidades))
#-------------------------------------------------------------------#Comienzo la interfaz de usuarioui <-
shinyUI(tabsetPanel( tabPanel("Producto Comparativo",pageWithSidebar( headerPanel("Proyecciones de Productos"), #Creo los inputs del sidebar sidebarPanel(uiOutput("pais"), uiOutput("año"), uiOutput("producto.maestro"), uiOutput("producto"), uiOutput("fecha.promo"), uiOutput("duracion")), mainPanel(textOutput("total.unidades"), plotOutput("grafica.comparativo")) )), tabPanel("Producto a proyectar")))
#Comienzo el archivo de servidor
server <- function(input, output) {require(ggplot2)require(shiny) output$pais = renderUI(selectInput(inputId = "pais", label = "Producto a comparar", choices = c("Seleccione un país",levels(data$Pais)), selected = "Seleccione un país") ) output$año = renderUI(selectInput(inputId = "año", label = NULL, choices = c("Seleccione un año",levels(data$Año)), selected = "Seleccione un año") ) # output$fecha.comparativo = renderUI( # dateRangeInput(inputId = "fecha.comparativo", # label = "¿Cuándo estuvo activo este producto?", # start = as.POSIXct(Sys.Date()-365), # end = as.POSIXct(Sys.Date()-1), # min = as.POSIXct("2014-01-01"), # max = as.POSIXct(Sys.Date() -1), # format = "dd/mm/yyyy", # separator = "a", # language = "es") # ) output$producto.maestro = renderUI( selectInput(inputId = "producto.maestro", label = NULL, choices = c("Seleccione un producto maestro",levels(factor(data$Producto.Maestro[which(data$Pais == input$pais & data$Año == input$año)]))), selected = "Seleccione un producto maestro") )
output$producto = renderUI( if(input$pais == "Seleccione un país" || input$año == "Seleccione un año" || input$producto.maestro == "Seleccione un producto maestro"){return(NULL) }else selectInput(inputId = "producto", label = NULL, choices = levels(factor(data$Producto[which(data$Pais == input$pais & data$Año == input$año & data$Producto.Maestro == input$producto.maestro)])), selected = levels(factor(data$Producto[which(data$Pais == input$pais & data$Año == input$año & data$Producto.Maestro == input$producto.maestro)])), multiple = TRUE) ) # output$fecha.promo = renderUI( # dateRangeInput(inputId = "fecha.promo", # label = "¿Cuándo va a lanzar su promoción?", # start = as.POSIXct(Sys.Date()), # end = as.POSIXct(Sys.Date() + 45), # min = as.POSIXct(Sys.Date()), # max = as.POSIXct(Sys.Date() + 365), # format = "dd/mm/yyyy", # separator = "a", # language = "es") # ) # output$duracion = renderText(paste("Duración de la promoción: ",input$fecha.promo[2] - input$fecha.promo[1]," días")) output$total.unidades = renderText( if(input$pais == "Seleccione un país" || input$año == "Seleccione un año" || input$producto.maestro == "Seleccione un producto maestro"){return() }else paste("Unidades vendidas del producto comparativo: ", prettyNum(sum(data$Unidades[which(data$Pais == input$pais & data$Año == input$año & data$Producto.Maestro == input$producto.maestro & data$Producto %in% input$producto)]),big.mark = ","))) df3 = reactive({(subset(data, data$Año == input$año & data$Pais == input$pais & data$Producto.Maestro == input$producto.maestro & data$Producto %in% input$producto))})
df4 = reactive({(setNames(aggregate(df3()$Unidades, by=list(df3()$Producto.Maestro, df3()$Fecha),FUN =sum), c("Producto.Maestro","Fecha","Unidades")))})
output$grafica.comparativo = renderPlot( if(input$pais == "Seleccione un país" || input$producto.maestro == "Seleccione un producto maestro" || is.na(input$producto.maestro)){return() } else print(ggplot(df4(), aes(x = Fecha, y = Unidades)) + geom_line(color = "black",size = 1)) )}
#Corro la aplicaciónshinyApp(ui = ui, server = server)
R version 3.3.2 (2016-10-31)Platform: x86_64-w64-mingw32/x64 (64-bit)Running under: Windows >= 8 x64 (build 9200)
locale:[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252
attached base packages:[1] stats graphics grDevices utils datasets methods base
other attached packages:[1] ggplot2_2.2.1 rsconnect_0.7 shiny_1.0.0
loaded via a namespace (and not attached): [1] Rcpp_0.12.9 packrat_0.4.8-1 assertthat_0.1 digest_0.6.12 bitops_1.0-6 [6] mime_0.5 grid_3.3.2 R6_2.2.0 plyr_1.8.4 jsonlite_1.2 [11] xtable_1.8-2 gtable_0.2.0 scales_0.4.1 lazyeval_0.2.0 labeling_0.3 [16] RJSONIO_1.3-0 tools_3.3.2 RCurl_1.95-4.8 munsell_0.4.3 httpuv_1.3.3 [21] colorspace_1.3-2 htmltools_0.3.5 tibble_1.2
Warning message:In value[[3L]](cond) : Failed to parse C:/Users/borja.sanz/AppData/Local/Temp/Rtmpm0vyek/filedf8fdd6ffc/app.R ; dependencies in this file will not be discovered.Introducir código aquí...
Preparing to deploy application...DONEUploading bundle for application: 159676...DONEDeploying bundle: 726855 for application: 159676 ...Waiting for task: 349328209 building: Parsing manifest building: Building image: 716453 building: Fetching packages building: Installing packages building: Installing files building: Pushing image: 716453 deploying: Starting instances rollforward: Activating new instances terminating: Stopping old instancesApplication successfully deployed to https://borjasanz.shinyapps.io/directorio_-_proyecciones_productos/Deployment completed: https://borjasanz.shinyapps.io/directorio_-_proyecciones_productos/
Warning message:In value[[3L]](cond) :
Failed to parse C:/Users/borja.sanz/AppData/Local/Temp/RtmpiSzsdR/file20149523cd2/app.R ; dependencies in this file will not be discovered.
2017-02-27T16:17:08.133898+00:00 shinyapps[159676]: 112: print
2017-02-27T16:17:08.133899+00:00 shinyapps[159676]: 111: renderPlot
2017-02-27T16:17:08.133899+00:00 shinyapps[159676]: 101: <reactive:plotObj>
2017-02-27T16:17:08.133899+00:00 shinyapps[159676]: 90: plotObj
2017-02-27T16:17:08.133900+00:00 shinyapps[159676]: 89: origRenderFunc
2017-02-27T16:17:08.133900+00:00 shinyapps[159676]: 88: output$grafica.comparativo
2017-02-27T16:17:08.133901+00:00 shinyapps[159676]: 12: fn
2017-02-27T16:17:08.133902+00:00 shinyapps[159676]: 11: doTryCatch
2017-02-27T16:17:08.133902+00:00 shinyapps[159676]: 9: tryCatchList
2017-02-27T16:17:08.133903+00:00 shinyapps[159676]: 8: tryCatch
2017-02-27T16:17:08.133903+00:00 shinyapps[159676]: 7: connect$retry
2017-02-27T16:17:08.133903+00:00 shinyapps[159676]: 6: eval
2017-02-27T16:17:08.133904+00:00 shinyapps[159676]: 5: eval
2017-02-27T16:17:08.133901+00:00 shinyapps[159676]: 13: runApp
2017-02-27T16:17:08.133902+00:00 shinyapps[159676]: 10: tryCatchOne
2017-02-27T16:17:08.133905+00:00 shinyapps[159676]: 1: local
2017-02-27T16:17:08.133905+00:00 shinyapps[159676]: 2: eval.parent
2017-02-27T16:17:08.133904+00:00 shinyapps[159676]: 4: eval
2017-02-27T16:17:08.133904+00:00 shinyapps[159676]: 3: eval
2017-02-27T16:23:59.136874+00:00 shinyapps[159676]: Server version: 1.1.0-116
2017-02-27T16:23:59.136922+00:00 shinyapps[159676]: LANG: es_GT.UTF-8
2017-02-27T16:23:59.136925+00:00 shinyapps[159676]: R version: 3.3.2
2017-02-27T16:23:59.136944+00:00 shinyapps[159676]: shiny version: 1.0.0
2017-02-27T16:23:59.136945+00:00 shinyapps[159676]: rmarkdown version: NA
2017-02-27T16:23:59.136971+00:00 shinyapps[159676]: knitr version: NA
2017-02-27T16:23:59.136997+00:00 shinyapps[159676]: jsonlite version: 1.2
2017-02-27T16:23:59.137025+00:00 shinyapps[159676]: RJSONIO version: NA
2017-02-27T16:23:59.137041+00:00 shinyapps[159676]: htmltools version: 0.3.5
2017-02-27T16:23:59.293974+00:00 shinyapps[159676]: Using jsonlite for JSON processing
2017-02-27T16:23:59.317145+00:00 shinyapps[159676]:
2017-02-27T16:23:59.317151+00:00 shinyapps[159676]: Listening on http://0.0.0.0:43642
2017-02-27T16:23:59.299967+00:00 shinyapps[159676]: Starting R with process ID: '17'
2017-02-27T16:23:59.299965+00:00 shinyapps[159676]:
2017-02-27T16:24:01.162411+00:00 shinyapps[159676]: Warning: Error in library: there is no package called ‘ggplot2’
2017-02-27T16:24:01.166589+00:00 shinyapps[159676]: Stack trace (innermost first):
2017-02-27T16:24:01.166591+00:00 shinyapps[159676]: 55: library
2017-02-27T16:24:01.166592+00:00 shinyapps[159676]: 54: server [/srv/connect/apps/directorio_-_proyecciones_productos/app.R#50]
2017-02-27T16:24:01.166592+00:00 shinyapps[159676]: 13: runApp
2017-02-27T16:24:01.166593+00:00 shinyapps[159676]: 12: fn
2017-02-27T16:24:01.166593+00:00 shinyapps[159676]: 11: doTryCatch
2017-02-27T16:24:01.166594+00:00 shinyapps[159676]: 10: tryCatchOne
2017-02-27T16:24:01.166594+00:00 shinyapps[159676]: 9: tryCatchList
2017-02-27T16:24:01.166595+00:00 shinyapps[159676]: 8: tryCatch
2017-02-27T16:24:01.166595+00:00 shinyapps[159676]: 7: connect$retry
2017-02-27T16:24:01.166596+00:00 shinyapps[159676]: 5: eval
2017-02-27T16:24:01.166596+00:00 shinyapps[159676]: 4: eval
2017-02-27T16:24:01.166597+00:00 shinyapps[159676]: 3: eval
2017-02-27T16:24:01.166598+00:00 shinyapps[159676]: 2: eval.parent
2017-02-27T16:24:01.166598+00:00 shinyapps[159676]: 1: local
2017-02-27T16:24:01.166795+00:00 shinyapps[159676]: Error in library(ggplot2) : there is no package called ‘ggplot2’
2017-02-27T16:24:01.166595+00:00 shinyapps[159676]: 6: eval