Leaflet 我第一次用地图、点和数学表达式学习R
下面你会发现我的第一个项目试图学习闪亮。 我正在努力实现以下想法:Leaflet 我第一次用地图、点和数学表达式学习R,leaflet,click,r-leaflet,new-project,Leaflet,Click,R Leaflet,New Project,下面你会发现我的第一个项目试图学习闪亮。 我正在努力实现以下想法: 用滑动条选择一个数字,并显示数学表达式的正确答案 有地图吗 在地图上插入一个点 读取csv(带有距离的数据,位于桌面上的csv) 从csv中选择我想要的类别,以便围绕地图中的点绘制一个圆 到目前为止,我已经实现了第一个3,但我真的很难找到一个解决方案,为接下来的两个。 有人能指导我怎么做吗 library(shiny) library(shinythemes) library(leaflet) df <- data.fra
library(shiny)
library(shinythemes)
library(leaflet)
df <- data.frame(longitude = 26, latitude = 39)
# Define UI for slider app ----
ui <- fluidPage(
#Navbar structure for UI
navbarPage("SAR Model", theme = shinytheme("united"),
tabPanel("Toblers Function", titlePanel("Toblers Function - Insert slope") ,
sidebarLayout(
sidebarPanel(
# Input: Slope interval with step value ----
sliderInput("slope", "Slope:",
min = -0.60, max = 0.50,
value = 0.0, step = 0.01)),
# Main panel for displaying outputs ----
mainPanel(
# Output: Table summarizing the values entered ----
tableOutput("Values"),
tableOutput("slope")))),
tabPanel("Map",titlePanel("SAR MAP - insert a point"),mainPanel(leafletOutput("map", width = "100%", height = "700"))),
tabPanel("Data",titlePanel("Data Summury"), dataTableOutput("table"))))
server <- function(input, output) {
# Reactive expression to create data frame off input value ----
sliderValues <- reactive({
data.frame(
Name = c("Slope"),
Value = as.character(c(input$slope)),
stringsAsFactors = TRUE)
})
# Show the values in an HTML table ----
output$values <- renderTable({
sliderValues()
})
output$slope <- renderText({
paste0("The speed is ", 6*exp(-3.5*abs(input$slope+0.05)),"Km/h")
})
output$map <- renderLeaflet({
leaflet() %>%addTiles()
})
df_r <- reactiveValues(new_data = df)
# reactive list with id of added markers
clicked_markers <- reactiveValues(clickedMarker = NULL)
observeEvent(input$map_click, {
click <- input$map_click
click_lat <- click$lat
click_long <- click$lng
clicked_markers$clickedMarker <- c(clicked_markers$clickedMarker, 1)
id <- length(clicked_markers$clickedMarker)
# Add the marker to the map
leafletProxy('map') %>%
addMarkers(lng = click_long, lat = click_lat, group = 'new_circles',
options = markerOptions(draggable = TRUE), layerId = id)
# add new point to dataframe
df_r$new_data <- rbind(rep(NA, ncol(df)), df_r$new_data)
df_r$new_data$longitude[1] <- click_long
df_r$new_data$latitude[1] <- click_lat
})
observeEvent(input$map_marker_mouseout,{
click_marker <- input$map_marker_mouseout
id <- input$map_marker_mouseout$id
if(click_marker$lng != df_r$new_data$longitude[id] | click_marker$lat != df_r$new_data$latitude[id]){ # why is this always true??
df_r$new_data$longitude[id] <- click_marker$lng
df_r$new_data$latitude[id] <- click_marker$lat
}
})
output$table <- renderDataTable({df_r$new_data})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinythemes)
图书馆(单张)
df