-
Notifications
You must be signed in to change notification settings - Fork 0
/
app2.R
199 lines (163 loc) · 5.96 KB
/
app2.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Preambulo ----
# options(rsconnect.packrat = TRUE)
# library(httr)
# set_config(use_proxy(url="10.3.100.207",port=8080))
library(shiny)
library(magrittr)
library(bslib)
# Datos ----
# especies <- read.csv("Valdivia_especies.csv")
especies <- read.csv("Especies_DiversidadFlora.csv")
head(especies)
# Interfaz de usuario ----
ui <-page_navbar(
theme = bs_theme( bg = "#f0f0f0", fg = "#000"),
position = "static-top",
## Titulo ----
title = tags$span(
class = "title",
tags$a(
tags$img(src = "botanicapp.JPG", height = "50px", style = "margin-top: -5px")
# href = "https://odes-chile.org"
),
"Aplicación para mejorar las habilidades de reconocimiento de especies nativas en Chile"
),
## Panel lateral ----
sidebar = sidebar(
width = 400,
### Familia ----
accordion(
open = "Familia",
accordion_panel(
"Familia", icon = icon("plant-wilt"),
uiOutput("acordion-familia"),
actionButton("abrir_btn", "Cargar fotografía", icon = icon("camera-retro")),
accordion_panel(
"Seleccione la familia", icon = icon("plant-wilt"),
uiOutput("seleccion_familia"),
selectInput("respuesta_familia", label = NULL,
choices=sort(unique(especies$FAMILY))),
actionButton("respuesta_btn_fam",label="Enviar respuesta", icon = icon("arrow-right")),
textOutput("valor_output_fam")),
actionButton("ayuda_btn_fam", "Usar una ayuda", icon = icon("searchengin")),
textOutput("ayuda_output_fam")
)
),
### Especie ----
accordion(
open = FALSE,
accordion_panel(
"Especie", icon = icon("leaf"),
uiOutput("acordion-especie"),
actionButton("abrir_btn_2", "Cargar fotografía", icon = icon("camera-retro")),
accordion_panel(
"Ingrese el nombre de la especie", icon = icon("leaf"),
uiOutput("seleccion_especie"),
textInput(inputId = "respuesta_especie", label = NULL,
placeholder = "Ingrese aquí su respuesta"),
actionButton("respuesta_btn_esp", "Enviar respuesta", icon = icon("arrow-right")),
textOutput("valor_output_esp")),
actionButton("ayuda_btn_esp", "Usar una ayuda", icon = icon("searchengin")),
textOutput("ayuda_output_esp")
)
)
)
,
## Panel principal ----
bslib::nav_panel(
title = "Cuestionario",
icon = icon("question"),
tags$head(
tags$link(href = "logo-botanicapp.png", rel = "icon")
),
layout_column_wrap(
width = 1,
class = "my-3",
imageOutput("imagen_output")
)
)
,
## Listado de especies ----
bslib::nav_panel(
title = "Listado de especies",
icon = icon("clipboard-list"),
layout_column_wrap(
width = 1,
navset_card_tab(
# height = 450,
full_screen = TRUE,
# title = "HTML Widgets",
nav_panel(
"Listado de especies",
tableOutput("tablaEspecies")
# includeMarkdown("md/ayuda.md")
)
)
)
)
)
# Servidor ----
server <- function(input, output, session) {
valores.reactivos <- reactiveValues()
valores.reactivos$contador <- 0
valores.reactivos$familia1 <- NA
observeEvent(input$abrir_btn | input$abrir_btn_2, {
img.name <- sample(unique(especies$Especie),1,replace = FALSE)# input$imagen
img_name <- gsub(pattern = " ", replacement = "_", x= img.name)
print(img_name)
print(img.name)
espp <- img.name
familiaa <- unique(especies$FAMILY[especies$Especie==espp])
print(familiaa)
reactiveValues(a=espp)
output$imagen_output <- renderImage({
list(src = paste0("images/",
sample(x = list.files("images/")[
grep(pattern = img_name,
x = list.files("images/"))],
1, replace = FALSE)),
alt = "Imagen",
# width = "80%"
height = "150%"
)
}, deleteFile = FALSE)
valores.reactivos$img1 <- espp
valores.reactivos$familia1 <- familiaa
})
print(valores.reactivos)
# Confirma valor de familia
verificarOpcion <- function() {
opcion_seleccionada <- input$respuesta_familia
if (opcion_seleccionada == valores.reactivos$familia1) {
return("¡La opción ingresada es Correcta!")
} else {
return("La opción ingresada es incorrecta.")
}
}
# verifica al hacer click
observeEvent(input$respuesta_btn_fam, {
valor_output_fam <- verificarOpcion()
output$valor_output_fam <- renderText({
valor_output_fam
})
})
ayuda1 <- reactive({
especies[especies$Especie==valores.reactivos$img1,c("ownhint_Description_1","ownhint_Description_2")][1,sample(1:2,1,replace = FALSE)]
}) %>% bindCache(input$abrir_btn) %>% bindEvent(input$ayuda_btn_fam)
output$ayuda_output_fam <- renderText(ayuda1())
respuesta2 <- reactive({
if(valores.reactivos$img1 == input$respuesta_especie){
"¡La opción ingresada es Correcta!"}else{"La opción ingresada es incorrecta."}
}) %>% bindCache(input$respuesta_especie) %>% bindEvent(input$respuesta_btn_esp)
output$valor_output_esp <- renderText(respuesta2())
ayuda2 <- reactive({
especies[especies$Especie==valores.reactivos$img1,c("ownhint_Description_1","ownhint_Description_2")][1,sample(1:2,1,replace = FALSE)]
}) %>% bindCache(input$abrir_btn) %>% bindEvent(input$ayuda_btn_esp)
output$ayuda_output_esp <- renderText(ayuda2())
output$tablaEspecies <- renderTable({
tabla.salida <- especies[,c("TAXONNAME", "GENUS", "FAMILY")]
names(tabla.salida) <- c("Nombre taxonómico", "Género", "Familia")
tabla.salida
})
}
shinyApp(ui, server)