问题
My app works correctly locally on my computer when I use runApp().
The problem is when I want to deploy it it gives me an error that it can't find a function: ERROR: no se pudo encontrar la función "dmy"
which translates to: ERROR: Could not find the function "dmy".
I know this function is part of lubridate (which I have locally) and I know I should install it in the server but I can't. I've looked around and I can't find where
library(lubridate)
should go.
Here is my code (sorry for the bad syntax but Im new in Shiny):
#Comienzo la aplicación
#Cargo las librerÃas
require(shiny)
require(rsconnect)
require(lubridate)
#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 datos
data<-read.csv("./data/Pruebas Shiny.csv")
#Obtengo los niveles de cada factor
Producto.Maestro = levels(data$Producto.Maestro)
Producto = levels(data$Producto)
Pais = levels(data$Pais)
#Cambio las fechas a formato de fecha
data$Fecha = dmy(data$Fecha)
#Extraigo el año
data$Año = as.factor(year(data$Fecha))
#Obtengo los niveles de Año
Años = levels(data$Año)
#-------------------------------------------------------------------
#Comienzo la interfaz de usuario
ui <-
shinyUI(pageWithSidebar(
headerPanel("Proyecciones de Productos"),
#Creo los inputs del sidebar
sidebarPanel(uiOutput("duracion"),
uiOutput("pais"),
uiOutput("año"),
uiOutput("producto.maestro"),
uiOutput("producto")),
mainPanel()
)
)
#Comienzo el archivo de servidor
require(shiny)
require(lubridate)
server <- function(input, output) {
output$duracion = renderUI(sliderInput(inputId = "duracion",
label = "Seleccione la duración de su promoción:",
value = 45, min = 15, max = 90)
)
output$pais = renderUI(selectInput(inputId = "pais",
label = "",
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$producto.maestro = renderUI(
selectInput(inputId = "producto.maestro",
label = NULL,
choices = c("Seleccione un producto maestro",levels(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()
}else selectInput(inputId = "producto",
label = NULL,
choices = c("Seleccione los productos relevantes",levels(factor(data$Producto[which(data$Pais == input$pais & data$Producto.Maestro == input$producto.maestro)]))),
selected = levels(factor(data$Producto[which(data$Pais == input$pais & data$Producto.Maestro == input$producto.maestro)])),
multiple = TRUE)
)
}
#Corro la aplicación
shinyApp(ui = ui, server = server)
回答1:
A work-around might be to use
lubridate::dmy() instead of loading the lubridate package with require() or library(). Doing so requires a little more typing, since you would need to replace any instance of dmy() with lubridate::dmy().
来源:https://stackoverflow.com/questions/42458780/error-could-not-find-function-dmy-when-deploying-app-to-shiny