这是indexloc提供的服务,不要输入任何密码
Skip to content

Interactive viewing tmap object in vscode terminal over remote SSH #987

@lmwang9527

Description

@lmwang9527

Not sure this is the right place for this, but just in case it'd helpful to anyone running into similar situation. I use vscode (and its variants) to do work on my server over remote-SSH. Oftentimes, I want to view interactive maps created used tmap in vscode Terminal (R or radian), but the maps would not show up in vscode Viewer tab. (mapview works out of the box for this use case.) I figured out a solution (with the help of Claude) by setting the viewer option:

options(viewer = function(url, ...) {
    # Extract the directory path from the URL
    dir_path <- dirname(gsub("file:///", "", url))
    # Start the server in that directory
    servr::httd(dir = dir_path, port = 4321, daemon = TRUE)
    # Open the file in browser using the server URL
    file_name <- basename(url)
    browseURL(paste0("http://localhost:4321/", file_name))
})

You can put it in .Rprofile with a check for interactive session and vscode terminal: if (interactive() && Sys.getenv("TERM_PROGRAM") == "vscode") {...}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions