-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.R
140 lines (127 loc) · 3.65 KB
/
layout.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
library(shiny)
library(leaflet)
ui <- fluidPage(
#css to hide radioButtons
tags$head(
tags$style(type="text/css",
".shiny-options-group {display:none}"
)),
radioButtons("radio","", choices = c(1:4)),
uiOutput("ui")
)
server <- function(input, output, session){
#observer to extract radio parameter from url
observe({
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query$radio)) {
updateRadioButtons(session, "radio", selected = as.numeric(query$radio))
}
})
#render different UIs depending on the radio button selected via the URL
output$ui <- renderUI({
if (input$radio == 4){
out <- tagList(
titlePanel("My fourth app"
),
tabsetPanel(
tabPanel("Tab 1",
sidebarLayout(
sidebarPanel(
numericInput("number", "Pick a number", value = 10),
selectInput("select", "Select an animal", choices = c("Cat", "Dog"))
),
mainPanel(
plotOutput("plot"),
tableOutput("table")
)
)
),
tabPanel("Tab 2",
fluidRow(
column(width = 3,
textInput("word", "Type a word"),
sliderInput("slider", "Pick a value", min = 10, max = 100, value = 50)
),
column(width = 6,
leafletOutput("map")
),
column(width = 3,
checkboxInput("check", "Tick me")
)
)
),
tabPanel("Tab 3",
plotOutput("another_plot")
)
))}
if (input$radio == 1){
out <- tagList(
titlePanel(
"My first Shiny app"
),
sidebarLayout(
sidebarPanel(
textInput("name", "What is your name?")
),
mainPanel(
plotOutput("plot")
)
)
)
}
if (input$radio == 2){
out <- tagList(
titlePanel(
"My second app"
),
tabsetPanel(
tabPanel("Tab 1",
sidebarLayout(
sidebarPanel(
textInput("name", "What is your name?")
),
mainPanel(
plotOutput("plot")
)
)),
tabPanel("Tab 2",
plotOutput("another_plot")
),
tabPanel("Tab 3",
leafletOutput("map")
)
)
)
}
if (input$radio == 3){
out <- tagList(
titlePanel( "My third app"),
fluidRow(
column(width = 3,
textInput("name", "What is your name?")
),
column(width = 6,
plotOutput("plot")
),
column(width = 3,
plotOutput("another_plot")
)
)
)
}
out
})
output$plot <- renderPlot(plot(iris$Sepal.Length, iris$Sepal.Width))
output$another_plot <- renderPlot(plot(iris$Petal.Length, iris$Petal.Width))
fcover <- terra::rast("exercise3/London_fcover_2023-06-10.tif")
wards <- sf::st_read("exercise3/London_Ward.shp", quiet = TRUE)
#reproject shapes to same CRS as the raster
wards <- sf::st_transform(wards, terra::crs(fcover))
output$map <- leaflet::renderLeaflet({
leaflet::leaflet() %>%
leaflet::addProviderTiles("Esri.WorldTopoMap") %>%
leaflet::addRasterImage(fcover) %>%
leaflet::addPolygons(data = wards, color = "black", weight = 1)
})
}
shinyApp(ui, server, options = list(port = 6110))