Skip to content

Commit a3a6d3d

Browse files
committed
new
1 parent df6665c commit a3a6d3d

File tree

4 files changed

+265
-0
lines changed

4 files changed

+265
-0
lines changed

Diff for: shiny_A.R

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
library(devtools)
4+
library(shiny)
5+
library(fullPage)
6+
7+
#demo("fullPage", package = "fullPage")
8+
#demo("pagePiling", package = "fullPage")
9+
#demo("multiPage", package = "fullPage")
10+
11+
12+
13+
ui <- fullPage(
14+
fullSection(
15+
menu = "first",
16+
center = TRUE,
17+
h1("Callbacks")
18+
),
19+
fullSection(
20+
menu = "second",
21+
center = TRUE,
22+
h3("Slice"),
23+
verbatimTextOutput("slide")
24+
)
25+
)
26+
27+
server <- function(input, output){
28+
29+
output$slide <- renderPrint({
30+
input$slide_origin # returns menu
31+
})
32+
33+
}
34+
35+
shinyApp(ui, server)

Diff for: shiny_AA.R

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
library(shiny)
3+
library(shinybulma)
4+
5+
shinyApp(
6+
ui = bulmaPage(
7+
bulmaHero(
8+
fullheight = TRUE,
9+
color = "primary",
10+
bulmaHeroBody(
11+
bulmaContainer(
12+
bulmaTitle("Shiny meets Bulma!"),
13+
bulmaSubtitle("A neat framework for your Shiny apps.")
14+
)
15+
)
16+
),
17+
bulmaSection(
18+
bulmaContainer(
19+
bulmaTileAncestor(
20+
bulmaTileParent(
21+
vertical = TRUE,
22+
bulmaTileChild(
23+
bulmaTitle("Tile 1"),
24+
p("Put some data here"),
25+
color = "link"
26+
),
27+
bulmaTileChild(
28+
bulmaTitle("Tile 2"),
29+
plotOutput("chart"),
30+
color = "danger"
31+
)
32+
),
33+
bulmaTileParent(
34+
vertical = TRUE,
35+
bulmaTileChild(
36+
bulmaTitle("Tile 3"),
37+
p("Put some data here"),
38+
color = "warning"
39+
),
40+
bulmaTileChild(
41+
bulmaTitle("Tile 3"),
42+
("Put some data here"),
43+
color = "info"
44+
)
45+
)
46+
)
47+
)
48+
)
49+
),
50+
server = function(input, output) {
51+
output$chart <- renderPlot({
52+
plot(x = runif(20, 5, 10), y = runif(20, 10, 12))
53+
})
54+
}
55+
)

Diff for: shiny_AAA.R

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#R group
2+
require(shiny)
3+
nameList=as.character(rownames(mtcars))
4+
5+
shinyUI <- fluidPage(
6+
7+
sidebarPanel(
8+
tags$head(tags$script(src="enterButton.js")),
9+
fluidRow(selectInput("name",label = "Model",choices = c("",nameList))),
10+
fluidRow(sliderInput("hp","Horsepower range",min =50 ,max=350,value=c(50,150))),
11+
fluidRow(actionButton("submit",label = "Submit"))
12+
),
13+
14+
mainPanel(
15+
dataTableOutput("res"),
16+
17+
conditionalPanel(
18+
condition="output.res",fluidRow(downloadLink("resTable","Download table"),
19+
fluidRow(downloadLink("priceList","Download price list")))
20+
)
21+
))
22+
23+
24+
25+
#R group
26+
require(shiny)
27+
28+
29+
30+
shinyServer <- function(input, output) {
31+
32+
res=eventReactive(input$submit,{
33+
34+
name=as.character(input$name)
35+
minHp=input$hp[1]
36+
maxHp=input$hp[2]
37+
38+
res=mtcars
39+
if (name!="") {
40+
res=mtcars[name,]
41+
}
42+
res=res[res$hp<maxHp & res$hp>minHp,]
43+
44+
validate(need(nrow(res)>0, "No matches found"))
45+
46+
return(res)
47+
48+
})
49+
50+
output$res=renderDataTable({
51+
res=res()
52+
},options=list(hover = T, bordered = T, align="c", colnames = T, rownames = T, na="NA"))
53+
54+
output$resTable=downloadHandler(filename="data_table.csv",
55+
content = function(file) {
56+
write.csv(res,file,row.names = F)
57+
}, contentType = "text/csv")
58+
59+
output$priceList=downloadHandler(filename = "cars_prices.csv",
60+
content=function(file){
61+
file.copy("price_list.csv")
62+
},contentType = "text/csv")
63+
64+
}
65+
66+
67+

Diff for: spatial_data.R

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
3+
suppressPackageStartupMessages(library(dplyr))
4+
library(stars)
5+
# Loading required package: abind
6+
# Loading required package: sf
7+
# Linking to GEOS 3.5.0, GDAL 2.2.2, PROJ 4.8.0
8+
tif = system.file("tif/L7_ETMs.tif", package = "stars")
9+
read_stars(tif) %>%
10+
slice(index = 1, along = "band") %>%
11+
plot()
12+
13+
14+
prec_file = system.file("nc/test_stageiv_xyt.nc", package = "stars")
15+
(prec = read_ncdf(prec_file, curvilinear = c("lon", "lat"), ignore_bounds = TRUE))
16+
17+
18+
################
19+
sf::read_sf(system.file("gpkg/nc.gpkg", package = "sf"), "nc.gpkg") %>%
20+
st_transform(st_crs(prec)) -> nc # transform from NAD27 to WGS84
21+
nc_outline = st_union(st_geometry(nc))
22+
plot_hook = function() plot(nc_outline, border = 'red', add = TRUE)
23+
prec %>%
24+
slice(index = 1:12, along = "time") %>%
25+
plot(downsample = c(5, 5, 1), hook = plot_hook)
26+
27+
28+
29+
a = aggregate(prec, by = nc, FUN = max)
30+
# although coordinates are longitude/latitude, st_intersects assumes that they are planar
31+
# although coordinates are longitude/latitude, st_intersects assumes that they are planar
32+
plot(a, max.plot = 23, border = 'grey', lwd = .5)
33+
34+
35+
36+
37+
index_max = function(x) ifelse(all(is.na(x)), NA, which.max(x))
38+
st_apply(a, "geometry", index_max) %>%
39+
mutate(when = st_get_dimension_values(a, "time")[.$index_max]) %>%
40+
select(when) %>%
41+
plot(key.pos = 1, main = "time of maximum precipitation")
42+
43+
44+
45+
46+
library(sf)
47+
library(leaflet)
48+
library(mapview)
49+
library(mapedit)
50+
library(leafpm)
51+
# make a contrived polygon with holes for testing
52+
outer1 = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
53+
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
54+
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
55+
outer2 = matrix(c(11,0,11,1,12,1,12,0,11,0),ncol=2, byrow=TRUE)
56+
pts1 = list(outer1, hole1, hole2)
57+
pts2 = list(outer2)
58+
pl1 = st_sf(geom = st_sfc(st_polygon(pts1)))
59+
pl2 = st_sf(geom = st_sfc(st_polygon(pts2)))
60+
mpl = st_sf(geom = st_combine(rbind(pl1, pl2)), crs=4326)
61+
tst = editFeatures(mpl, editor = "leafpm")
62+
# look at our creation
63+
mapview(tst)
64+
65+
66+
67+
68+
library(sp)
69+
grd = SpatialPoints(expand.grid(x=1:100, y=1:100))
70+
gridded(grd) = TRUE
71+
fullgrid(grd) = TRUE
72+
pts = spsample(grd, 50, "random")
73+
pts$z = rnorm(50)
74+
library(gstat)
75+
v = vgm(1, "Sph", 90)
76+
out = krige(z~1, pts, grd, v, nmax = 20, nsim = 4)
77+
78+
## drawing 4 GLS realisations of beta...
79+
## [using conditional Gaussian simulation]
80+
81+
out[[3]] = 0.5 * out[[3]] + 0.5 * rnorm(1e4)
82+
out[[4]] = rnorm(1e4)
83+
spplot(out, as.table = TRUE)
84+
85+
86+
87+
library(tmap)
88+
budapest_df = data.frame(name = "Budapest", x = 19, y = 47.5)
89+
class(budapest_df)
90+
#> [1] "data.frame"
91+
budapest_sf = sf::st_as_sf(budapest_df, coords = c("x", "y"))
92+
class(budapest_sf)
93+
#> [1] "sf" "data.frame"
94+
tmap_mode("view")
95+
#> tmap mode set to interactive viewing
96+
m = tm_shape(budapest_sf) + tm_dots() + tm_view(basemaps = "OpenStreetMap",
97+
set.view = 9)
98+
tmap_leaflet(m)
99+
100+
101+
102+
103+
library(tmap)
104+
tm_shape(nz) +
105+
tm_polygons("Median_income", palette = "RdYlBu")
106+
107+
108+

0 commit comments

Comments
 (0)