ERROR: Could not find function “dmy” when Deploying App to Shiny

给你一囗甜甜゛ 提交于 2020-01-03 05:00:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!