Xihan YAO commited on
Commit
267753b
1 Parent(s): 4c71b1b

first deploy

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. Dockerfile +4 -6
  3. app.R +33 -49
  4. demo_288.Rproj +13 -0
.gitignore CHANGED
@@ -1 +1,2 @@
1
  .DS_Store
 
 
1
  .DS_Store
2
+ .Rproj.user
Dockerfile CHANGED
@@ -1,16 +1,14 @@
 
1
  FROM rocker/shiny-verse:latest
2
 
3
  WORKDIR /code
4
 
5
  # Install stable packages from CRAN
6
- RUN install2.r --error \
7
- ggExtra \
8
- shiny
9
 
10
  # Install development packages from GitHub
11
- RUN installGithub.r \
12
- rstudio/bslib \
13
- rstudio/httpuv
14
 
15
  COPY . .
16
 
 
1
+ ?runApp
2
  FROM rocker/shiny-verse:latest
3
 
4
  WORKDIR /code
5
 
6
  # Install stable packages from CRAN
7
+ RUN install2.r --error ggExtra shiny spData terra stars leaflet.extra
 
 
8
 
9
  # Install development packages from GitHub
10
+ RUN installGithub.r rstudio/leaflet
11
+
 
12
 
13
  COPY . .
14
 
app.R CHANGED
@@ -1,58 +1,42 @@
1
- library(shiny)
2
- library(bslib)
3
- library(dplyr)
4
- library(ggplot2)
 
 
5
 
6
- df <- readr::read_csv("penguins.csv")
7
- # Find subset of columns that are suitable for scatter plot
8
- df_num <- df |> select(where(is.numeric), -Year)
9
-
10
- ui <- page_sidebar(
11
- theme = bs_theme(bootswatch = "minty"),
12
- title = "Penguins explorer",
13
- sidebar = sidebar(
14
- varSelectInput("xvar", "X variable", df_num, selected = "Bill Length (mm)"),
15
- varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
16
- checkboxGroupInput("species", "Filter by species",
17
- choices = unique(df$Species), selected = unique(df$Species)
18
- ),
19
- hr(), # Add a horizontal rule
20
- checkboxInput("by_species", "Show species", TRUE),
21
- checkboxInput("show_margins", "Show marginal plots", TRUE),
22
- checkboxInput("smooth", "Add smoother"),
23
- ),
24
- plotOutput("scatter")
25
  )
26
 
27
- server <- function(input, output, session) {
28
- subsetted <- reactive({
29
- req(input$species)
30
- df |> filter(Species %in% input$species)
31
- })
32
 
33
- output$scatter <- renderPlot(
34
- {
35
- p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) +
36
- theme_light() +
37
- list(
38
- theme(legend.position = "bottom"),
39
- if (input$by_species) aes(color = Species),
40
- geom_point(),
41
- if (input$smooth) geom_smooth()
42
- )
43
 
44
- if (input$show_margins) {
45
- margin_type <- if (input$by_species) "density" else "histogram"
46
- p <- p |> ggExtra::ggMarginal(
47
- type = margin_type, margins = "both",
48
- size = 8, groupColour = input$by_species, groupFill = input$by_species
49
- )
50
- }
51
 
52
- p
53
- },
54
- res = 100
55
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
57
 
58
  shinyApp(ui, server)
 
1
+ library(shiny) # for shiny apps
2
+ library(leaflet) # renderLeaflet function
3
+ library(spData) # loads the world dataset
4
+ library(terra)
5
+ library(stars)
6
+ library(leaflet.extras2)
7
 
8
+ ui = fluidPage(
9
+ leafletOutput(outputId = "map")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  )
11
 
 
 
 
 
 
12
 
13
+ before_fire_tifs <- "/vsicurl/https://huggingface.co/spaces/cboettig/shiny-app/resolve/main/before_fire/cube_d36238205702022-05-25.tif"
14
+ after_fire_tifs <- "/vsicurl/https://huggingface.co/spaces/cboettig/shiny-app/resolve/main/after_fire/cube_d36482e5462022-05-30.tif"
15
+ before_fire_nbr <- read_stars(before_fire_tifs)
16
+ after_fire_nbr <- read_stars(after_fire_tifs)
17
+ dnbr <- before_fire_nbr - after_fire_nbr
 
 
 
 
 
18
 
 
 
 
 
 
 
 
19
 
20
+ server = function(input, output) {
21
+ output$map = renderLeaflet({
22
+ #https://trafficonese.github.io/leaflet.extras2/reference/addSidebyside.html
23
+
24
+ # addRasterImage options requires pre-release leaflet....
25
+ stopifnot(compareVersion(as.character(packageVersion("leaflet")), "2.2.1") > 0)
26
+
27
+ Map <- leaflet() |>
28
+ addMapPane("right", zIndex = 0) |>
29
+ addMapPane("left", zIndex = 0) |>
30
+ addTiles(group = "base", layerId = "baseid1", options = pathOptions(pane = "right")) |>
31
+ addTiles(group = "base", layerId = "baseid2", options = pathOptions(pane = "left")) |>
32
+ addRasterImage(x = rast(after_fire_nbr), options = leafletOptions(pane = "right"), group = "r1") |>
33
+ addRasterImage(x = rast(before_fire_nbr), options = leafletOptions(pane = "left"), group = "r2") |>
34
+ addLayersControl(overlayGroups = c("r1", "r2")) |>
35
+ addSidebyside(layerId = "sidecontrols",
36
+ rightId = "baseid1",
37
+ leftId = "baseid2")
38
+
39
+ })
40
  }
41
 
42
  shinyApp(ui, server)
demo_288.Rproj ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Version: 1.0
2
+
3
+ RestoreWorkspace: Default
4
+ SaveWorkspace: Default
5
+ AlwaysSaveHistory: Default
6
+
7
+ EnableCodeIndexing: Yes
8
+ UseSpacesForTab: Yes
9
+ NumSpacesForTab: 2
10
+ Encoding: UTF-8
11
+
12
+ RnwWeave: knitr
13
+ LaTeX: pdfLaTeX