在闪亮的应用程序中绘制GoogleMaps

2023-11-21

我认为在一个闪亮的应用程序中使用plotGoogleMaps来使用R动态分析和显示空间数据会非常酷。我以前从未使用过这两个包(它们相对较新)并且没有太多的编程经验,所以我从每个的教程和示例,然后尝试将它们混合在一起。

我可以让代码的所有单独元素正常工作,但运行应用程序不会显示谷歌地图。我猜这与plotGoogleMaps尝试在浏览器中绘图以及shiny尝试在浏览器中渲染绘图有关,但我不知道如何解决这个问题。我从中提取了大部分闪亮的代码闪亮的教程输入和输出并遵循绘图GoogleMaps 教程

测试代码:

#load packages and data
library(shiny)
library(plotGoogleMaps)
data(meuse)

#convert data frame to SpatialPointDataFrame and set 
coordinates(meuse)<-~x+y
proj4string(meuse) <- CRS('+init=epsg:28992')

#will need to select column name for app, maybe not best way to do this, 
#but seems to work
formulaText<-paste('zinc')

#plot data on Google map, opens browser and works
mpgPlot <- plotGoogleMaps(meuse, zcol=formulaText)

ui.R

library(shiny)

# Define UI for meuse test
shinyUI(pageWithSidebar(

    # Application title
    headerPanel("Meuse Test"),

    # Sidebar with controls to select the variable to plot on map
    sidebarPanel(
        selectInput("variable", "Variable:",
                                choices=list("Zinc" = "zinc", 
                                         "Lead" = "lead", 
                                         "Copper" = "copper"), 
                                selected="Zinc")

    ),

    # Show the caption and plot of the requested variable on map
    mainPanel(
        plotOutput("mapPlot")
    )
))

server.R

library(shiny)
library(plotGoogleMaps)

data(meuse)
coordinates(meuse)<-~x+y
proj4string(meuse) <- CRS('+init=epsg:28992')

# Define server logic required to plot various variables on map
shinyServer(function(input, output) {

    # Compute the forumla text in a reactive expression since it is 
    # shared by the output$mapPlot ?I think I still need to do this...
    formulaText <- reactive({
#paste the input name in so it follows argument format for plotGoogleMaps?
#tried without, don't think it is probelm, works with test code...
        paste(input$variable)
    })


    # Generate a plot of the requested variable against mpg and only 
    # include outliers if requested
    output$mapPlot <- renderPlot({
        plotGoogleMaps(meuse, zcol=formulaText)
#also tried to specify alternative arguments like add=TRUE, 
#filename='mapPlot.htm', openMap=FALSE
    })
})

我知道shiny和plotGoogleMaps都是相当新的,我已经看到了一些向shiny Google群组发布问题的建议,但我不想重复发帖,StackOverflow是我寻求答案的地方。我最后还想为迄今为止为我提供了很多帮助的社区做出一点小小的贡献!如果这只是一个糟糕的方法,我愿意接受替代方案,我现在正在查看 googleVis...

谢谢, 亚历克斯

PS-

sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] googleVis_0.4.3    plotGoogleMaps_2.0 maptools_0.8-25   
[4] lattice_0.20-15    foreign_0.8-54     rgdal_0.8-10      
[7] sp_1.0-11          shiny_0.6.0       

loaded via a namespace (and not attached):
[1] bitops_1.0-5   caTools_1.14   digest_0.6.3   httpuv_1.0.6.3
[5] Rcpp_0.10.4    RJSONIO_1.0-3  tools_3.0.1    xtable_1.7-1 

PPS-我读过这个帖子在发帖前好几次,但现在我怀疑我的答案是否在那里。如果问题重复,请道歉。我认为这与htmlOutput()... ?htmlOutput稀疏……我感觉浓密……


谢谢拉姆纳特夫的代码我设法嵌入plotGoogleMaps在没有任何 .html 编程知识的情况下闪亮:

library(plotGoogleMaps)
library(shiny)

runApp(list(
  ui = pageWithSidebar(
   headerPanel('Map'),
   sidebarPanel(""),
   mainPanel(uiOutput('mymap'))
   ),
   server = function(input, output){
    output$mymap <- renderUI({
      data(meuse)
      coordinates(meuse) = ~x+y
      proj4string(meuse) <- CRS("+init=epsg:28992")
      m <- plotGoogleMaps(meuse, filename = 'myMap1.html', openMap = F)
      tags$iframe(
        srcdoc = paste(readLines('myMap1.html'), collapse = '\n'),
        width = "100%",
        height = "600px"
      )
    })
   }
))

请注意,不显示图例。我已经发布了有关此问题的问题别处。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在闪亮的应用程序中绘制GoogleMaps 的相关文章

  • 如何在 nlme 与 lme4 中指定不同的随机效应?

    我想使用指定模型中的不同随机效应nlme lme 数据在底部 随机效应是 1 intercept and position变化超过subject 2 intercept变化超过comparison 这很简单 使用lme4 lmer lmer
  • R grep:有 AND 运算符吗?

    假设我有以下数据框 User Id Tags 34234 imageUploaded people jpg more comma separated stuff 34234 imageUploaded 12345 people jpg 我如
  • 使用 R 中的晶格为 xyplot 中的每个面板添加不同的垂直线

    我有一个按年份排列的几个站点的植物物种频率图 我正在使用 grid 包中的 xyplot 绘制这些站点 我已经弄清楚如何获取每个物种位点组合的散点图 但是 我想添加一个 abline 代表进行化学处理的每年 每个地点在不同年份添加了化学处理
  • ggplot2错误:美学必须是长度一,或者与数据长度相同问题:颜色、字母

    我收到此错误 错误 美学必须是长度一 或者与数据长度相同问题 颜色 字母 当我将 ggplot 与数据框一起使用时Z如图所示 Z lt data frame Name c A G C T T T AG AG GC GC CT CT AT A
  • 如何与 R 包 sf 进行“完整”联合

    我尝试使用三个多边形之间的并集sf st union 下图中显示了 ArcGIS Overlay Union All 的结果 我希望通过使用 R 中的 sf 包获得与 OUTPUT 中五个不同多边形类似的结果 library sf a1 l
  • 根据R中的行差异对行进行分组[重复]

    这个问题在这里已经有答案了 我有一组具有不同采样间隔的动物位置 我想要做的是采样间隔符合特定标准 例如低于特定值 的组和序列 让我用一些虚拟数据来说明 start lt Sys time timediff lt c rep 5 3 20 r
  • R 中的约束优化

    我正在尝试使用http rss acs unt edu Rdoc library stats html constrOptim html http rss acs unt edu Rdoc library stats html constr
  • 如何使用字符对象使用 dplyr 重命名列[重复]

    这个问题在这里已经有答案了 我想通过使用变量以动态方式使用 dplyr 重命名列 但是 它只是为列命名变量的名称 而不是其内容 有任何想法吗 colnames y 1 time channel 1 channel 2 channel 3 c
  • 使用变量标签作为标题和轴标题时自动化 ggplots

    我对 NSE 和绘图函数有点混淆 我试图在使用变量标签 而不是名称 标记轴等的同时自动绘制一些图 假设我们有一个大型数据集 所有变量都已标记 这里的小例子 library tidyverse library sjlabelled libra
  • 如何在 R 中关闭管道连接之前获取输出?

    在 R 中 我们可以使用以下命令打开管道连接pipe 并写信给它 我观察到以下情况 我不太明白 让我们使用一个python管道例如 z pipe python open w cat x 1 n file z cat print x n fi
  • 导入 mgcv 失败,因为找不到 Rlapack.dll

    我想通过使用链接到 IronPython 中的 R 统计包R NET http rdotnet codeplex com 图书馆 它一直工作得很好 但现在我需要使用 R 的mgcv http cran r project org web p
  • 如何更改 ESS 中的智能分配键(“_”到“<-”)绑定

    在 emacs ESS 中 如何正确更改 ess smart S assign 的键绑定 我尝试的是添加 custom set variables ess smart S assign key to my emacs 但这让奇怪的事情发生了
  • 保存 d3heatmap 生成的热图

    我正在尝试保存由d3heatmap https github com rstudio d3heatmap转换为 pdf 文件 但文件总是损坏 library d3heatmap pdf file heat pdf d3heatmap mtc
  • 如何向 ggplot 标题和标题添加图标?

    现在我正在尝试将图标放入 ggplot 可视化中 为此 我在网上检查了一些教程 当我运行 Claus Wilke 的以下代码示例时 library ggtext library ggplot2 ggplot mtcars aes mpg d
  • 从 R 文本中提取网站链接

    我有多个文本 每个文本都可能包含对一个或多个网络链接的引用 例如 text1 s 1212a as www abcd com asasa11 我如何提取 www abcd com 来自 R 中的这段文字 换句话说 我希望提取以www并结束于
  • 在 RGUI 中自动保存 R 源

    是否可以告诉 RGui 自动保存 R 源代码 以便它们在系统崩溃时不会丢失 我非常怀念这个功能 因为我的系统时不时地崩溃 而且我不想仅仅因为需要这个功能而使用 R Studio 或其他一些 IDE 我喜欢 RGui 提供的简单性 None
  • R Shinydashboard 根据选项卡选择显示/隐藏 UI 元素

    如果有人可以提供帮助 我正在努力满足要求 我必须根据用户的选项卡面板选择在仪表板侧栏上显示 隐藏一些元素 这是 UI 代码的一部分 可让您了解我的应用程序的结构 我需要仅在 tabpPanel 2 上显示 Fourthoutput Fift
  • 加载 plyr 包时出现问题

    我使用 R 2 13 1 但未能成功尝试在 R 中加载包 plyr 1 6 我已将其手动安装到目录 R library 中 我的代码是 libPaths R library library plyr 我收到消息 库 plyr 中的错误 pl
  • 将缺失的行添加到数据表中

    我有一个数据表 library data table f lt data table id1 c 1 2 3 1 2 3 id2 as factor c a a b c b d v 1 6 key c id1 id2 id1 id2 v 1
  • 如果在循环中调用summary()命令,如何获得它的输出?

    Suppose Z是特征名称的向量 如何让以下 Rscript 中的摘要命令实际打印 for var in Z cat i form paste crim var lm fit lm form data Boston summary lm

随机推荐