Ho pensato che sarebbe stato fantastico usare plotGoogleMaps in un'app lucida per analizzare e visualizzare dinamicamente i dati spaziali usando R. Non ho mai usato alcun pacchetto prima (sono relativamente nuovi) e non hanno molto esperienza di programmazione, così ho iniziato con le esercitazioni e gli esempi per ciascuno e poi ho provato a mescolarli insieme.plotGoogleMaps nell'app lucida
Posso far funzionare tutti i singoli elementi del codice, ma l'esecuzione dell'app non mostra la mappa di google. Immagino che abbia a che fare con plotGoogleMaps che tenta di tracciare in un browser e che sta cercando di renderizzare la trama in un browser, ma non so come risolverlo. Ho tirato la maggior parte del codice di lucido da the shiny tutorial Inputs & Outputs e seguii il codice plotGoogleMaps Tutorial
prova:
#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
})
})
Capisco sia lucido e plotGoogleMaps sono piuttosto nuovi e ho visto alcuni suggerimenti posta domande al gruppo di Google lucido, ma non voglio raddoppiare post e StackOverflow è il mio go per le risposte. Finalmente vorrei anche dare un piccolo contributo a una comunità che mi ha aiutato così tanto finora! Se questo è solo un approccio pessimo Sono aperto alle alternative, sto controllando googleVis ora ...
Grazie, Alex
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 ho letto this post diverse volte prima di postare, ma ora sono sospettoso la mia risposta è lì. Appologie se la domanda è duplice. Penso che sia qualcosa con htmlOutput()
... ?htmlOutput
è scarsa ... Mi sento denso ...
Grazie per la tua risposta veloce! Non riesco a trovare 'plotGoogleVis', c'è 'plotGoogleMap' (sto usando) c'è 'googleVis' (ho detto) ... iframe sembra utile, nuovo territorio, cercherò di tornare ... I anche non sapeva di Leaflet, se entrambi i lavori accetteranno. Grazie! –