ShinyとleafletでWebアプリケーション
library(shiny)
library(dplyr)
library(lubridate)
library(stringr)
library(leaflet)
library(ggplot2)
library(plotly)
# データの定義
X <- read.csv(file="yockney-et-al-data-for-poned1439135.csv")
head(X)
X <- X %>%
mutate(NZDT_datetime=dmy_hm(NZDT_datetime)) %>%
arrange(NZDT_datetime) %>%
mutate(Latitude=if_else(Latitude>0, -1*Latitude, Latitude)) %>%
mutate(Animal.code=str_to_upper(Animal.code), Season=str_to_upper(Season))
head(X)
X$popup <- paste("HDOP=", X$HDOP, sep="")
Animal.code <- unique(X$Animal.code)
# UIの定義
ui <- fluidPage(
a(titlePanel("possum-foraging"), href="https://data.world/nz-govt/possum-foraging"),
sidebarLayout(
sidebarPanel=sidebarPanel(
selectInput(inputId="Animal.code", label="Animal.code", choices=Animal.code, selected=Animal.code[1])
),
mainPanel=mainPanel(
leafletOutput(outputId="leaflet"),
plotlyOutput(outputId="histogram"),
plotlyOutput(outputId="linepoint")
)
)
)
# サーバの定義
server <- function(input, output, session){
output$leaflet <- renderLeaflet({
x <- X %>% filter(Animal.code==input$Animal.code)
leaflet() %>% addTiles() %>%
addPolylines(lng=x$Longitude, lat=x$Latitude, weight=1, popup=input$Animal.code, color="blue") %>%
addCircles(lng=x$Longitude, lat=x$Latitude, radius=0.5, popup=x$popup, color="blue")
})
output$histogram <- renderPlotly({
x <- X %>% filter(Animal.code==input$Animal.code)
p <- ggplot(data=x, mapping=aes(x$HDOP)) + geom_histogram(fill="blue") + xlab(label="HDOP")
ggplotly(p)
})
output$linepoint <- renderPlotly({
x <- X %>% filter(Animal.code==input$Animal.code)
p <- ggplot(x, aes(x=NZDT_datetime, y=HDOP)) + geom_line(color="blue") + geom_point(color="blue")
ggplotly(p)
})
}
# アプリケーションの起動
shinyApp(ui=ui, server=server)
Author And Source
この問題について(ShinyとleafletでWebアプリケーション), 我々は、より多くの情報をここで見つけました https://qiita.com/yono2844/items/68e1c1e4e9191da50bfd著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .