resp <- getToken(
id = Sys.getenv("client_id"),
secret = Sys.getenv("client_secret"),
scope = "data:read"
)
myToken <- resp$content$access_token
myEncodedUrn <- jsonlite::base64_enc(Sys.getenv("urn"))6 Viewer
The AutoDesk Viewer is a WebGL-based 3D model browser that runs entirely in the browser. With AutoDeskR, you can embed it in a Shiny app with a single function call, no JavaScript required. Rotate, zoom, and inspect your models without leaving R.
Before launching the viewer, you need a file translated to SVF format and its encoded URN. The Model Derivative chapter covers both steps.
6.1 Launch the Viewer
viewer3D() opens a Shiny app with the viewer pre-loaded. The viewerType parameter controls the UI chrome:
viewerType |
What you get |
|---|---|
"header" |
Full toolbar, navigation panels, and settings (default) |
"headless" |
Viewer canvas only — clean embed for dashboards |
"vr" |
WebVR mode, optimised for mobile |
APS requires URNs to be Base64-encoded before use in any API call. jsonlite::base64_enc() handles this. See Model Derivative for a full explanation.
# Full viewer — great for exploration
viewer3D(urn = myEncodedUrn, token = myToken)
# Headless — embed in a dashboard without the toolbar chrome
viewer3D(urn = myEncodedUrn, token = myToken, viewerType = "headless")
# VR mode for a phone or headset
viewer3D(urn = myEncodedUrn, token = myToken, viewerType = "vr")When you run viewer3D() in RStudio or a browser, a WebGL viewport opens and you can rotate, zoom, and click elements to inspect their properties. The viewer renders whatever SVF translation produced: layer geometry for DWG files, full BIM elements for Revit.
6.2 Embed in a Shiny App
viewerUI() drops the viewer into any Shiny layout as a module. The id parameter namespaces the module so multiple viewers can live on the same page without stepping on each other.
library(shiny)
library(AutoDeskR)
ui <- fluidPage(
viewerUI("viewer1", urn = myEncodedUrn, token = myToken)
)
server <- function(input, output, session) {}
shinyApp(ui, server)6.2.1 Viewer in a Tab Panel
Headless mode is perfect for a multi-tab layout. The viewer sits in one tab and data tables or charts in another:
ui <- fluidPage(
tabsetPanel(
tabPanel("Model",
viewerUI("viewer1", myEncodedUrn, myToken, viewerType = "headless")
),
tabPanel("Metadata",
verbatimTextOutput("meta")
),
tabPanel("Layer Chart",
plotOutput("layer_plot")
)
)
)
server <- function(input, output, session) {
output$meta <- renderPrint({
# getData() results displayed alongside the viewer
})
}
shinyApp(ui, server)6.2.2 Viewer + Sensor Dashboard
Pair the headless viewer with a dygraphs time-series panel for a live digital twin layout. See the Live Dashboards chapter for the full implementation:
library(dygraphs)
ui <- fluidPage(
fluidRow(
column(7, viewerUI("twin_viewer", myEncodedUrn, myToken, viewerType = "headless")),
column(5, dygraphOutput("sensor_plot", height = "500px"))
)
)6.3 Responding to Element Selection
When a user clicks an element in the viewer, viewerUI() writes its dbId to a Shiny input named <id>_selection. Use this to drive the rest of your app reactively — show the element’s properties, highlight a matching row in a table, or fetch related sensor data:
library(shiny)
library(AutoDeskR)
ui <- fluidPage(
titlePanel("Model Explorer"),
fluidRow(
column(7,
viewerUI("viewer1", urn = myEncodedUrn, token = myToken,
viewerType = "headless")
),
column(5,
h4("Selected element"),
verbatimTextOutput("element_props")
)
)
)
server <- function(input, output, session) {
selected_props <- reactive({
req(input$viewer1_selection) # dbId of the clicked element
resp <- getData(
guid = myGuid,
urn = myEncodedUrn,
token = myToken
)
coll <- resp$content$data$collection
match <- Filter(function(x) x$objectid == input$viewer1_selection, coll)
if (length(match)) match[[1]]$properties else list()
})
output$element_props <- renderPrint({
str(selected_props())
})
}
shinyApp(ui, server)myGuid comes from getMetadata() — see Model Derivative. You only need to fetch it once at app startup, not inside the reactive.
6.4 What’s Displayed
The viewer renders whatever the SVF translation produced. For a DWG file, that’s the full drawing geometry organised by layer. For a Revit file, it’s the full BIM model with element properties accessible in the side panel. Click any element in the viewer to inspect its properties, the same data that getData() returns programmatically.