-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ejemplo.R
63 lines (55 loc) · 1.59 KB
/
Ejemplo.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
library(shiny)
library(shinythemes)
library(ggplot2)
library(plotly)
library(leaflet)
library(DT)
qDat <- distritos
qDat$id <- seq.int(nrow(qDat))
str(qDat)
ui <- fluidPage(
titlePanel("Programa Municipal de Desarrollo"),
sidebarPanel(
h4('Proyectos Estratégicos'),
selectInput("subsistema",
"Subsistema:",
unique(c('Todos', c(proyectos$SUBSISTEMA))),
selected = 'Todos')),
mainPanel(
leafletOutput('map01'),
dataTableOutput('table01'))
)
server <- function(input,output){
qSub <- st_drop_geometry(qDat)
# table
output$table01 <- renderDataTable({
DT::datatable(qSub, selection = "single",options=list(stateSave = TRUE))
})
# to keep track of previously selected row
prev_row <- reactiveVal()
observeEvent(input$table01_rows_selected, {
row_selected = qSub[input$table01_rows_selected,]
proxy <- leafletProxy('map01')
#print(row_selected)
proxy %>%
addPolygons(data = distritos[input$table01_rows_selected,],
color = 'red')
})
# map
output$map01 <- renderLeaflet({
qMap <- leaflet() %>%
addTiles() %>%
addPolygons(data = distritos,
layerId = ~id)
qMap
})
observeEvent(input$map01_shape_click, {
print(input$table01)
print(input$map01_shape_click)
clickId <- input$map01_shape_click$id
dataTableProxy("table01") %>%
selectRows(qSub[which(qSub$id_dto.x == clickId),])
#selectPage(qSub[which(input$table01_rows_all == clickId),] %/% input$table01_state$length + 1)
})
}
shinyApp(ui = ui, server = server)