Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 如何在闪亮的应用程序中将传单地图点击(事件)与绘图创建连接起来_Events_Shiny_Leaflet_R Leaflet - Fatal编程技术网

Events 如何在闪亮的应用程序中将传单地图点击(事件)与绘图创建连接起来

Events 如何在闪亮的应用程序中将传单地图点击(事件)与绘图创建连接起来,events,shiny,leaflet,r-leaflet,Events,Shiny,Leaflet,R Leaflet,您好,我正在创建一个环境闪亮应用程序,其中我想使用传单地图创建一些基于openair pac的简单绘图kagehttps://rpubs.com/NateByers/Openair. Aq_测量通用表格 met <- importNOAA(code = "12345-12345", year = YYYYY:YYYY) AQ这里是一个最小的例子。你点击你的标记,你会得到一个绘图 ui = fluidPage( leafletOutput("map"), textOutput("t

您好,我正在创建一个环境闪亮应用程序,其中我想使用传单地图创建一些基于openair pac的简单绘图kagehttps://rpubs.com/NateByers/Openair.

Aq_测量通用表格

met <- importNOAA(code = "12345-12345", year = YYYYY:YYYY)

AQ这里是一个最小的例子。你点击你的标记,你会得到一个绘图

ui = fluidPage(
  leafletOutput("map"),
  textOutput("temp"),
  plotOutput('tim')
)

#server.r

#df$location <- gsub( " " , "+" , df$location)
server = function(input, output, session) {


  output$map <- renderLeaflet({
    leaflet(df)%>% addTiles() %>% addMarkers(lng = longitude, lat = latitude)
  })

  output$temp <- renderPrint({

    input$map_marker_click$lng
  })

  output$tim <- renderPlot({
    temp <- df %>% filter(longitude == input$map_marker_click$lng)
   # timeVariation(temp, pollutant = "value")
    print(ggplot(data = temp, aes(longitude, latitude)) + geom_point())
  })


}

shinyApp(ui = ui, server = server)

不清楚你想要什么。比如你想要什么样的情节?您还应该提供一个简单的示例。可能更容易得到帮助。你的代码很长,有点凌乱,很难理解。我编辑它是为了展示你如何用openair绘图。这不是问题所在,因为情节非常简单。我基本上想做的是用传单的交互性来取代输入$loc的功能性。我希望rt函数在单击地图时将其值作为输入,而不是作为示例使用的selectInput。如果您运行代码,您将在第一个选项卡中的某些位置激活所有内容。我想要这个功能,但要看地图。这里的技巧2可能会给出一个我希望的功能性概念。当然,我可以说方向是正确的,但我想问:为什么你只使用液化天然气?还有像这样的东西吗?rt%aq\u measurementslocation=~location,date\u from=~firstUpdated,date\u to=~lastUpdated我说过我不清楚你想要什么。所以我从底部开始。你点击一个点,你得到你的绘图。从这里开始,添加要实现的过滤器将更容易。我不知道为什么地点仍然处于被动功能,因为单击地图会显示位置。我只使用了经度,假设它是唯一的,但如果需要,也可以添加纬度{temp%filterlongity==input$map\u marker\u click$lng%>%aq\u measurementcountry=~国家,位置=~位置,日期\u from=~首次更新,日期\u to=~上次更新,参数=input$met错误:'match'需要向量参数
library(shiny)
library(leaflet)
library(plotly)
library(shinythemes)
library(htmltools)
library(DT)
library(utilr)
library(openair)
library(plotly)
library(dplyr)
library(ggplot2)
library(gissr)
library(ropenaq)
library(worldmet)

# Define UI for application that draws a histogram
   ui = navbarPage("ROPENAQ",
           tabPanel("CREATE DATAFRAME",
                    sidebarLayout(

                      # Sidebar panel for inputs ----
                      sidebarPanel(
                        wellPanel(
                          uiOutput("loc"),
                          helpText("Choose a Location to create the dataframe.")
                        )
                        ),
                      mainPanel(

                      )
                    )
           ),
           tabPanel("LEAFLET MAP",
                    leafletOutput("map"),
                    wellPanel(
                      uiOutput("dt"),
                      uiOutput("dt2"),
                      helpText("Choose a start and end date for the dataframe creation. Select up to 2 dates")
                    ),
                    "Select your Pollutant",
                    uiOutput("pollutant"),                     

                    helpText("While all pollutants are listed here, not all pollutants are measured at all locations and all times.  
                             Results may not be available; this will be corrected in further revisions of the app.  Please refer to the measurement availability 
                             in the 'popup' on the map."),

                    hr(),
                    fluidRow(column(8, plotOutput("tim")),
                             column(4,plotOutput("polv"))),
                    hr(),

                    fluidRow(column(4, plotOutput("win")),
                             column(8,plotOutput("cal"))),
                    hr(),
                    fluidRow(column(12, plotOutput("ser"))
                             )
           )


)

#server.r

# load data
# veh_data_full <- readRDS("veh_data_full.RDS")
# veh_data_time_var_type <- readRDS("veh_data_time_var_type.RDS")
df$location <- gsub( " " , "+" , df$location)
server = function(input, output, session) {

    output$pollutant<-renderUI({
      selectInput("pollutant", label = h4("Choose Pollutant"), 
                  choices = colnames(df[,6:8]), 
                  selected = 1)
    })


    #Stores the value of the pollutant selection to pass to openAQ request      

    ###################################
   #output$OALpollutant <- renderUI({OALpollutant})


    ##################################
    # create the map, using dataframe 'locations' which is polled daily (using ropenaq)
    #MOD TO CONSIDER: addd all available measurements to the popup - true/false for each pollutant, and dates of operation.


    output$map <- renderLeaflet({
      leaflet(subset(df,(df[,input$pollutant]=="TRUE")))%>% addTiles() %>%
        addMarkers(lng = subset(df,(df[,input$pollutant]=="TRUE"))$longitude, lat = subset(df,(df[,input$pollutant]=="TRUE"))$latitude,
                   popup = paste("Location:", subset(df,(df[,input$pollutant]=="TRUE"))$location, "<br>",
                                 "Pollutant:", input$pollutant, "<br>",
                                 "First Update:", subset(df,(df[,input$pollutant]=="TRUE"))$firstUpdated, "<br>",
                                 "Last Update:", subset(df,(df[,input$pollutant]=="TRUE"))$lastUpdated
                                 ))
    })
    #Process Tab
   OAL_site <- reactive({
        req(input$map_marker_click)
        location %>%
            filter(latitude == input$map_marker_click$lat,
                   longitude == input$map_marker_click$lng)

###########
        #call Functions for data retrieval and processing.  Might be best to put all data request
        #functions into a seperate single function.  Need to:
        # call importNOAA() to retrieve meteorology data into temporary data frame
        # call aq_measurements() to retrieve air quality into a temporary data frame
        # merge meteorology and air quality datasets into one working dataset for computations; temporary
        # meteorology and air quality datasets to be removed.
        # call openAir() functions to create plots from merged file.  Pass output to a dashboard to assemble 
        # into appealing output.
        # produce output, either as direct download, or as an emailable PDF.
        # delete all temporary files and reset for next run.
    })
   #fun 

   output$loc<-renderUI({
     selectInput("loc", label = h4("Choose location"),
                 choices = df$location ,selected = 1
     )
   })

   output$dt<-renderUI({

                 dateInput('date',
                           label = 'First Available Date',
                           value = subset(df$firstUpdated,(df[,1]==input$loc))
                 )           


   })
   output$dt2<-renderUI({

                 dateInput('date2',
                           label = 'Last available Date',
                           value = subset(df$lastUpdated,(df[,1]==input$loc))
                 )            


   })

   rt<-reactive({


     AQ<- aq_measurements(location = input$loc, date_from = input$dt,date_to = input$dt2,parameter = input$pollutant)
     met <- importNOAA(year = 2014:2018)
     colnames(AQ)[9] <- "date"
     merged<-merge(AQ, met, by="date")
     # date output -- reports user-selected state & stop dates in UI
     merged$location <- gsub( " " , "+" , merged$location)

     merged


   })
   #DT  

     output$tim = renderPlot({
       timeVariation(rt(), pollutant = "value")
     })


}

shinyApp(ui = ui, server = server)
output$map <- renderLeaflet({
      leaflet(subset(locations,(locations[,input$pollutant]=="TRUE")))%>% addTiles() %>%
        addMarkers(lng = subset(locations,(locations[,input$pollutant]=="TRUE"))$longitude, lat = subset(locations,(locations[,input$pollutant]=="TRUE"))$latitude,
                   popup = paste("Location:", subset(locations,(locations[,input$pollutant]=="TRUE"))$location, "<br>",
                                 "Pollutant:", input$pollutant, "<br>",
                                 "First Update:", subset(locations,(locations[,input$pollutant]=="TRUE"))$firstUpdated, "<br>",
                                 "Last Update:", subset(locations,(locations[,input$pollutant]=="TRUE"))$lastUpdated
                   ))
    })  

  output$dt<-renderUI({

                 dateInput('date',
                           label = 'First Available Date',
                           value = subset(locations$firstUpdated,(locations[,1]==input$loc))
                 )           


   })
   output$dt2<-renderUI({

                 dateInput('date2',
                           label = 'Last available Date',
                           value = subset(locations$lastUpdated,(locations[,1]==input$loc))
                 )            


   })


   rt<-reactive({



     AQ<- aq_measurements(location = input$loc, date_from = input$dt,date_to = input$dt2)
     met <- importNOAA(year = 2014:2018)
     colnames(AQ)[9] <- "date"
     merged<-merge(AQ, met, by="date")
     # date output -- reports user-selected state & stop dates in UI
     merged$location <- gsub( " " , "+" , merged$location)

     merged


   })
   #DT  










     output$tim = renderPlot({
       timeVariation(rt(), pollutant = "value")
     })         
ui = fluidPage(
  leafletOutput("map"),
  textOutput("temp"),
  plotOutput('tim')
)

#server.r

#df$location <- gsub( " " , "+" , df$location)
server = function(input, output, session) {


  output$map <- renderLeaflet({
    leaflet(df)%>% addTiles() %>% addMarkers(lng = longitude, lat = latitude)
  })

  output$temp <- renderPrint({

    input$map_marker_click$lng
  })

  output$tim <- renderPlot({
    temp <- df %>% filter(longitude == input$map_marker_click$lng)
   # timeVariation(temp, pollutant = "value")
    print(ggplot(data = temp, aes(longitude, latitude)) + geom_point())
  })


}

shinyApp(ui = ui, server = server)