-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
56 lines (53 loc) · 1.79 KB
/
app.R
File metadata and controls
56 lines (53 loc) · 1.79 KB
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
library(leaflet)
library(RSQLite)
library(shiny)
db=dbConnect(SQLite(), dbname="mapdata.sqlite")
dbSendQuery(conn=db,
"CREATE TABLE Map
(Country TEXT,
Emotion TEXT)")
dbSendQuery(conn=db,
"INSERT INTO Map
VALUES ('Germany', 'Happiness')")
dbSendQuery(conn=db,
"INSERT INTO Map
VALUES ('input$Country', 'input$Emotion')")
dbListFields(db, "Map")
dbDisconnect(db)
country_names=data@data$sovereignt
dat=data@data
chloro.palette = colorFactor(palette = c("#bbe7ff", "#ffc88c", "#bdf38d", "#fff6aa"), domain=data@data$mood)
mood=cbind("country"=country_names, "Joy"=0, "Anger"=0, "Fear"=0, "Grief"=0)
# Define UI ---- elements that are displayed on the page
ui <- fluidPage(
titlePanel("How do you feel?"),
sidebarLayout(
sidebarPanel(
h2("Your Country"),
selectInput("Country", "Choose your country:", choices = country_names),
selectInput("Emotion", "Choose your emotion:", choices=c("Joy", "Anger", "Fear", "Grief")),
actionButton("Button1", label = "Submit")
tableOutput()
),
mainPanel(
h1("How does the World feel?"),
leafletOutput("mymap")
)
)
)
# Define server logic ---- what are inputs and outputs
server <- function(input, output, session) {
output$mymap=renderLeaflet({
#output options must be saved to output$ and must be build with render function
#render function builds reactive output to display in UI
leaflet(data=dat) %>%
addTiles() %>%
addPolygons(data=data, weight=2, color = ~chloro.palette(data@data$mood)) %>%
addLegend("topright", pal = chloro.palette, values = ~mood,
title = "Mood",
opacity = 1) %>%
addScaleBar(position="topleft")
})
}
# Run the app ----
shinyApp(ui = ui, server = server)