将值从谷歌地图转移到闪亮应用程序中的rchart

时间:2014-07-02 08:01:39

标签: javascript r google-maps shiny plotgooglemaps

我有一个闪亮的应用程序,我用plotGoogleMapsrChart绘制地图,其值与 通过rPlot呈现地图中的某些标记。

应用用户可以点击地图中的标记来显示工具提示。

我希望当他点击标记时,图表中的相关值会突出显示。

有人知道如何执行此任务吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

@ jdharrison

R代码可以是这样的:

suppressPackageStartupMessages(library(googleVis))

## Hurricane Andrew (1992) storm track with Google Maps
AndrewMap <- gvisMap(Andrew, "LatLong", "Tip", options = list(showTip = TRUE, 
showLine = TRUE, enableScrollWheel = TRUE, mapType = "hybrid", useMapTypeControl = TRUE))

print(AndrewMap, "chart")

该示例来自here。您可以下载包here。在此示例中,使用了库 googleVis ,但我认为答案可能类似。

有光泽的例子

server.R

# Author: Denis Petrov
# Date: 2014-07-04

# Example is based on http://rpubs.com/gallery/googleVis

library (shiny)
suppressPackageStartupMessages (library (googleVis))

# Define server logic required to summarize and view the selected dataset
shinyServer ( function (input, output, session) 
{
  GetDataAndrew <- function ()
  {

    # Hurricane Andrew (1992) storm track with Google Maps
    AndrewMap <- gvisMap (Andrew, "LatLong", "Tip", 
                         options = list(showTip = TRUE, 
                                        showLine = TRUE, 
                                        enableScrollWheel = TRUE, 
                                        mapType = "hybrid", 
                                        useMapTypeControl = TRUE))

    return (AndrewMap)

  }

  output$viewchart <- renderGvis({
    GetDataAndrew ()
  })

  output$info <- renderPrint ({
    cat ('Hurricane\n')
    cat ('Pressure=937\n')
    cat ('Speed=120')
  })

}
)

ui.R

# Author: Denis Petrov
# Date: 2014-07-04


# Define UI for dataset viewer application
shinyUI(pageWithSidebar(

  # Application title
  headerPanel('Hurricane Andrew (1992)'),

  # Sidebar with controls to provide a caption, select a dataset, and 
  # specify the number of observations to view. Note that changes made
  # to the caption in the textInput control are updated in the output
  # area immediately as you type
  sidebarPanel(
               p ('Hurricane Andrew (1992) storm track with Google Maps'),
               p ('I would like the following output be changed based on 
                  selected pin.'),
               verbatimTextOutput ('info')
  ),


  # Show the caption, a summary of the dataset and an HTML table with
  # the requested number of observations
  mainPanel(
    htmlOutput ('viewchart')
  )
))