-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
156 lines (131 loc) · 4.16 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
library(shiny)
library(DT)
source("R/function_fd_esm_carbon.R")
# Define o UI
ui <- fluidPage(
# Adiciona uma barra superior estilizada
tags$head(includeHTML("static/ggan.html")),
tags$head(
tags$style(HTML("
.container-fluid {
background-color: #f8f9fa;
border-radius: 10px;
}
.btn-primary {
background-color: #007bff;
border-color: #007bff;
}
.btn-primary:hover {
background-color: #0056b3;
border-color: #004085;
}
.well {
background-color: #f0f4f7;
}
.shiny-input-container {
margin-bottom: 10px;
}
"))
),
# Título do aplicativo
titlePanel("Função estoque de carbono", windowTitle = "FD ESM Carbon"),
sidebarLayout(
# Sidebar com inputs organizados
sidebarPanel(
h3("Configurações do Arquivo"),
fileInput("file", "Selecione o arquivo Excel:", accept = c(".xlsx")),
textInput("sheet", "Nome da aba (sheet) no arquivo:", "aba"),
hr(),
h3("Parâmetros"),
numericInput("min_core_length_cm", "Comprimento mínimo do núcleo (cm):", 0, min = 0),
checkboxInput("extrapolation", "Habilitar extrapolação?", TRUE),
textInput("ESM_depths_cm", "Profundidades ESM (cm):", "5,10,20,30,50,75,100"),
hr(),
actionButton("run", "Executar", class = "btn btn-primary"),
downloadButton("download", "Baixar resultado", class = "btn btn-success")
),
# Painel principal com resultados
mainPanel(
h3("Resultados"),
verbatimTextOutput("output"),
DTOutput(outputId = "base")
)
),
tags$footer(
"Fonte:",
tags$a(
"Adam C. von Haden, Wendy H. Yang, Evan H. DeLucia",
target = "_blank",
href = "https://onlinelibrary.wiley.com/doi/full/10.1111/gcb.15124/"
),
style = "position: absolute; width: 100%; color: black; text-align: center;"
),
br(),
br(),
tags$footer(
style = "position: absolute; width: 100%; color: black; text-align: center;",
tags$link(rel = "icon", href = "hex.png", type = "image/x-icon"),
tags$img(
src = "https://gustavofrosi.com.br/ima/FS.png", # Caminho da logo (coloque a logo na pasta 'www')
alt = "Logo",
style = "height: 50px; vertical-align: center; margin-right: 10px;"
),
# Texto
tags$p(
"Desenvolvido por:",
tags$a(
href = "https://gustavofrosi.com.br/",
target="_top", "Gustavo Frosi"
)
)
)
)
# Define o server
server <- function(input, output, session) {
# Caminho temporário para o arquivo gerado
result_path <- reactiveVal(NULL)
result_data <- reactiveVal(NULL) # Para armazenar dados resultantes
observeEvent(input$run, {
req(input$file)
# Verifica os inputs
file <- input$file$datapath
sheet <- input$sheet
min_core_length_cm <- input$min_core_length_cm
extrapolation <- input$extrapolation
ESM_depths_cm <- as.numeric(unlist(strsplit(input$ESM_depths_cm, ",")))
# Define o caminho temporário para salvar o arquivo
temp_output <- tempfile(fileext = ".xlsx")
# Executa a função
tryCatch({
result <- fd_esm_carbon(
file = file,
sheet_in_file = sheet,
min_core_length_cm = min_core_length_cm,
extrapolation = extrapolation,
ESM_depths_cm = ESM_depths_cm,
save = TRUE,
output_filename = temp_output
)
# Salva os dados e o caminho do arquivo
result_path(temp_output)
result_data(result) # Atualiza com os dados de resultado
output$output <- renderText("Execução bem-sucedida! O arquivo está pronto para download.")
}, error = function(e) {
output$output <- renderText(paste("Erro na execução:", e$message))
})
# Exibe a tabela de resultados
# output$base <- renderDT( result_data() |> as.data.frame())
})
# Download do arquivo gerado
output$download <- downloadHandler(
filename = function() {
"resultado_fd_esm_carbon.xlsx"
},
content = function(file) {
req(result_path())
file.copy(result_path(), file)
}
)
}
# Roda o app
shinyApp(ui, server)