您可以定义
actionButton
其具有
onclick
活动。在那里,我们阅读了当前的文本
textInput
(使用
txt = document.getElementById('text').value;
)然后将其传递到剪贴板
navigator.clipboard.writeText(txt);
:
---
title: "Test"
format: dashboard
server: shiny
---
## Test
```{r}
library(shiny)
```
```{r}
#| title: "Text that needs to copy to clipboard"
# Text Input 1
textInput("text", "Enter Your Text")
actionButton(
"copy_link",
"Copy to clipboard",
onclick = "
txt = document.getElementById('text').value;
navigator.clipboard.writeText(txt);"
)
```
```{r}
#| context: server
```