Skip to contents

An R package that creates interactive Google Street View widgets using htmlwidgets. Drop Street View panoramas into R Markdown documents, Shiny apps, and Xaringan slide decks.

Installation

# install.packages("devtools")
devtools::install_gitlab("mhaffner/streetview")

Or from source (this directory):

devtools::install(".")

Prerequisites

You need a Google Maps JavaScript API key with the Maps JavaScript API and Street View Static API enabled. Get one at console.cloud.google.com.

Set it as an environment variable so you never hard-code it:

# In ~/.Renviron
GOOGLE_MAPS_API_KEY=AIza...

Then reload with readRenviron("~/.Renviron").

Usage

Interactive widget

library(streetview)

# Eiffel Tower
streetview(lat = 48.8584, lng = 2.2945)

# Custom heading / pitch
streetview(
  lat     = 40.7580,
  lng     = -73.9855,
  heading = 210,
  pitch   = -10,
  zoom    = 1,
  height  = "500px"
)

Static image URL / tag

# Returns a URL string
url <- sv_static_url(48.8584, 2.2945)

# Returns an <img> tag (ready for R Markdown)
sv_static_img(48.8584, 2.2945, size = "640x400")

Xaringan integration

htmlwidgets are embedded directly in Xaringan HTML slides — no iframes needed. Just include a widget in a code chunk:

---
title: "My Presentation"
output: xaringan::moon_reader
---

```{r echo=FALSE}
library(streetview)
streetview(lat = 48.8584, lng = 2.2945, height = "450px")
```

The widget’s JavaScript is inlined into the slide HTML automatically.

Note: The Google Maps API is loaded at runtime from maps.googleapis.com, so the viewer needs an internet connection. For fully offline slides, use sv_static_img() instead (static images are fetched once at render time).

Multiple widgets on one slide

Multiple streetview() calls on the same page share a single Maps API script load. The API key from the first widget is used.

Shiny

library(shiny)
library(streetview)

ui <- fluidPage(
  numericInput("lat", "Latitude",  value = 48.8584),
  numericInput("lng", "Longitude", value = 2.2945),
  streetviewOutput("pano")
)

server <- function(input, output) {
  output$pano <- renderStreetview({
    streetview(lat = input$lat, lng = input$lng)
  })
}

shinyApp(ui, server)

Function reference

Function Description
streetview() Interactive panorama widget
streetviewOutput() Shiny UI output placeholder
renderStreetview() Shiny server render function
sv_static_url() Static image URL string
sv_static_img() Static image <img> tag

streetview() parameters

Parameter Default Description
lat, lng Coordinates
api_key $GOOGLE_MAPS_API_KEY Maps API key
heading 0 Camera bearing (0–360°)
pitch 0 Camera tilt (−90 to 90°)
zoom 1 Zoom level (0–3)
pano_id NULL Direct panorama ID (overrides lat/lng)
address_control TRUE Show address overlay
fullscreen_control TRUE Show fullscreen button
link_control TRUE Show navigation arrows
pan_control TRUE Show compass control
zoom_control TRUE Show zoom buttons
width, height "100%", "400px" Widget size