我希望此应用程序在点击后立即将坐标复制到剪贴板.
换句话说,我想摆脱复制按钮.
如果不可能,我希望在传单弹出窗口中出现复制按钮.
library(shiny)
library(bslib)
library(rclipboard)
library(leaflet)
base_map <- leaflet() |>
addTiles()
# The UI
ui <- bslib::page_fluid(
rclipboardSetup(),
# Add a text input
textInput("copytext", "Copy this:", "Co-Ordinates!"),
# UI ouputs for the copy-to-clipboard buttons
uiOutput("clip"),
# A text input for testing the clipboard content.
textInput("paste", "Paste here:"),
leafletOutput("map")
)
# The server
server <- function(input, output, session) {
# Add clipboard buttons
output$clip <- renderUI({
rclipButton(
inputId = "clipbtn",
label = "rclipButton Copy",
clipText = input$copytext,
icon = icon("clipboard"),
)
})
output$map <- renderLeaflet(base_map)
observe({
click <- input$map_click
text <- paste0(click$lat, ", ", click$lng)
leafletProxy("map") |>
addPopups(
lat = click$lat,
lng = click$lng,
popup = text
)
updateTextInput(session, "copytext", value = text)
}) |>
bindEvent(input$map_click)
}
shinyApp(ui, server)