obtener_base = function(encuesta) {
if (input$Uplodatear) {
# req(input$Descarga) -> No tiene sentido por ser un boton
# Cual es el proposito de esto?
write.csv("NOHAYWEANOHAY", tempfile("NOHAYWEANOHAY"))
url = obtener_url_base(encuesta)
hash = obtener_hash_base(encuesta)
hash_archivos = tools::md5sum(dir(tempdir(), full.names = TRUE))
hash_archivos = hash_archivos[!is.na(hash_archivos)]
archivo_ya_descargado = FALSE
for (i in seq(length(hash_archivos))) {
if (hash_archivos[[i]] == hash) {
temp = names(hash_archivos)[[i]]
archivo_ya_descargado = TRUE
break
}
}
if (!archivo_ya_descargado) {
temp = tempfile(pattern = "datos")
check = tryCatch(
utils::download.file(url, temp),
error = function(cnd) {
cat("Error en la descarga.\n")
cat("Mensaje obtenido.\n")
cat(cnd$message)
},
warning = function(cnd) {
cat("Error en la descarga.\n")
cat("Mensaje obtenido.\n")
cat(cnd$message)
}
)
}
nombres = utils::unzip(temp, list = TRUE)[, "Name", drop = TRUE]
base = leer_base(encuesta, temp, nombres)
return(base)
} else {
# req(input$Upload) -> No tiene sentido porque es un boton
df = tryCatch({
utils::read.table(
input$file$datapath,
sep = input$sep1,
dec = input$dec1,
header = TRUE,
fill = TRUE
)
},
error = function(cnd) {
showModal(
modalDialog(
"Por favor, revise las opciones",
title = "Error en la carga de datos",
footer = NULL,
easyClose = TRUE
)
)
return(NULL)
},
warning = function(cnd) {
showModal(
modalDialog(
"Por favor, revise las opciones",
title = "Error en la carga de datos",
footer = NULL,
easyClose = TRUE
)
)
return(NULL)
})
if (encuesta == "ENFR") {
# Eliminar pesos de la base usuario ENFR cargada manualmente
# PORQUE?
df[, colnames(df) %in% c("wf1p","wf2p","wf3p")] = list(NULL)
}
return(df)
}
}
#### Replicas ####
obtener_base_replicas = function(encuesta) {
if (input$Uplodatear) {
# req(input$Descarga) -> No tiene sentido por ser un boton
url = obtener_url_replicas(encuesta)
hash = obtener_hash_replicas(encuesta)
hash_archivos = tools::md5sum(dir(tempdir(), full.names = TRUE))
hash_archivos = hash_archivos[!is.na(hash_archivos)]
archivo_ya_descargado = FALSE
for (i in seq(length(hash_archivos))) {
if (hash_archivos[[i]] == hash) {
temp = names(hash_archivos)[[i]]
archivo_ya_descargado = TRUE
break
}
}
if (!archivo_ya_descargado) {
temp = tempfile(pattern = "datos")
check = tryCatch(
utils::download.file(url, temp),
error = function(cnd) {
cat("Error en la descarga.\n")
cat("Mensaje obtenido.\n")
cat(cnd$message)
},
warning = function(cnd) {
cat("Error en la descarga.\n")
cat("Mensaje obtenido.\n")
cat(cnd$message)
}
)
}
nombres = utils::unzip(temp, list = TRUE)[, "Name", drop = TRUE]
base = leer_base_replicas(encuesta, temp, nombres)
return(base)
} else {
base = tryCatch({
utils::read.table(
input$file2$datapath,
sep = input$sep2,
dec = input$dec2,
header = TRUE,
fill = TRUE
)
},
error = function(cond) {
showModal(
modalDialog(
"Por favor, revise las opciones",
title = "Error en la carga de datos",
footer = NULL,
easyClose = TRUE
)
)
return(NULL)
},
warning = function(cond){
showModal(
modalDialog(
"Por favor, revise las opciones",
title = "Error en la carga de datos",
footer = NULL,
easyClose = TRUE
)
)
return(NULL)
})
return(base)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.