The streetview package creates interactive Google Street View panoramas as htmlwidgets. In an HTML R Markdown document, a widget renders as a fully interactive panorama. In a PDF or Word document, it falls back gracefully to a static image.
Setup
You need a Google Maps API key with the Maps JavaScript API and Street View Static API enabled. Get one at console.cloud.google.com.
Add it to ~/.Renviron:
GOOGLE_MAPS_API_KEY=AIza...
Then run readRenviron("~/.Renviron") to load it in the
current session. After that, streetview() picks up the key
automatically — no need to pass api_key in every call.
Basic usage
# Iso Roobertinkatu in Helsinki, Finland
streetview(lat = 60.1625, lng = 24.9394)The widget is fully interactive: click and drag to pan, scroll to zoom, and click the arrows to move along the street.
Controlling the camera
heading (0–360°, compass bearing), pitch
(−90–90°, vertical tilt), and zoom (0–3) set the opening
view:
# Vredenburg Crossing in Utrecht, Netherlands
streetview(
lat = 52.0930,
lng = 5.1133,
heading = 120,
pitch = 5,
zoom = 1,
height = "800px"
)Sizing the widget
width defaults to "100%" (fills the
document column). height defaults to "400px".
Pass any valid CSS value:
## Downtown Eau Claire, Wisconsin
streetview(lat = 44.81121, lng = -91.49969, height = "300px")Hiding UI controls
For a cleaner embed — e.g. when the panorama is illustrative rather than interactive — suppress the navigation chrome:
# NW Portland, Oregon
streetview(
lat = 45.52641,
lng = -122.68938,
address_control = FALSE,
fullscreen_control = FALSE,
link_control = FALSE,
pan_control = FALSE,
zoom_control = FALSE,
height = "320px"
)Static images
For non-interactive contexts — thumbnails, PDF reports, Word documents, or emails — use the static image helpers.
sv_static_url() builds the API URL:
sv_static_url(lat = 48.8584, lng = 2.2945, size = "640x400", heading = 150)sv_static_img() returns a ready-to-display
<img> tag:
sv_static_img(lat = 48.8584, lng = 2.2945, size = "640x300")Static images are fetched at render time and can be embedded as base64 by knitr, making them work in self-contained HTML, PDF, and Word outputs alike.
PDF and Word output
streetview() widgets require a browser to render. In PDF
or Word output, omit the widget and use sv_static_img()
instead. You can branch on the output format with
knitr::is_html_output():
Shiny
Use streetviewOutput() in the UI and
renderStreetview() on the server:
library(shiny)
library(streetview)
ui <- fluidPage(
titlePanel("Street View Explorer"),
sidebarLayout(
sidebarPanel(
numericInput("lat", "Latitude", value = 48.8584, step = 0.001),
numericInput("lng", "Longitude", value = 2.2945, step = 0.001),
sliderInput("heading", "Heading (°)", 0, 360, 0, step = 5),
sliderInput("pitch", "Pitch (°)", -90, 90, 0, step = 5)
),
mainPanel(
streetviewOutput("pano", height = "500px")
)
)
)
server <- function(input, output) {
output$pano <- renderStreetview({
streetview(
lat = input$lat,
lng = input$lng,
heading = input$heading,
pitch = input$pitch
)
})
}
shinyApp(ui, server)