我有一个
aceEditor
和 rclipboard
按钮。这个应用程序工作正常,我的意思是,当我单击按钮时,aceEditor
内的代码被复制到剪贴板中:
library(shiny)
library(shinyAce)
library(rclipboard)
ui<-basicPage(
rclipboardSetup()
,aceEditor(
outputId = "aceEdId",
mode="java",
theme="cobalt",
readOnly = F,
height = "300px",
tabSize = 1,
value = "some code"
)
,uiOutput("clip")
)
server <- function(input, output) {
output$clip <- renderUI({
rclipButton(
inputId = "clipbtn",
label = "rclipButton Copy",
clipText = input[["aceEdId"]],
icon = icon("clipboard"),
tooltip = "Click me... I dare you!",
placement = "top",
options = list(delay = list(show = 800, hide = 100), trigger = "hover")
)
})
}
shinyApp(ui, server)
现在,我有一个数据表(只有一条记录),其中每一行都有一个按钮。这些按钮打开一个
modal
,其中包含另一个数据表(只有一行)。当我单击此数据表的任何行时,会显示 aceEditor
以及复制到剪贴板的按钮。
library(shiny)
library(shinyAce)
library(rclipboard)
shinyInput <- function(FUN, n, id, ...) {
vapply(seq_len(n), function(i){
as.character(FUN(paste0(id, i), ...))
}, character(1))
}
ui<-fluidPage(
DTOutput('tbl1')
,rclipboardSetup()
)
server <- function(input, output) {
output$tbl1=renderDT({
a=data.frame("col"=c(1))
a$btb=shinyInput(
FUN = actionButton,
n = nrow(a),
id = 'btb_',
label = "Button",
onclick = 'Shiny.setInputValue(\"btn_Modal\", this.id, {priority: \"event\"})',
)
a
},selection = 'single',escape = FALSE)
observeEvent(input$btn_Modal, {
showModal(modalDialog(
rclipboardSetup()
,DTOutput('tbl2')
,uiOutput('uiOut')
))
})
observeEvent(input$tbl2_cell_clicked,{
req(!is.na(input$tbl2_cell_clicked))
output[["uiOut"]]<-renderUI({
basicPage(
rclipboardSetup()
,aceEditor(
outputId = "aceEdId",
value = "some code"
)
,uiOutput("clip")
)
})
})
output$tbl2=renderDT({
a=data.frame("col"=c(1))
a
},selection = 'single')
output$clip <- renderUI({
rclipButton(
inputId = "clipbtn",
label = "rclipButton Copy",
clipText = input[["aceEdId"]]
)
})
}
shinyApp(ui, server)
但在这种情况下,复制到剪贴板的按钮不起作用。它没有显示任何错误,只是不复制任何内容。有什么建议吗?
它有效。但我没有尝试使用 DT 表。
library(shiny)
library(shinyAce)
library(rclipboard)
ui <- fluidPage(
rclipboardSetup(),
actionButton("openModal", "Show modal")
)
server <- function(input, output, session) {
# Add clipboard buttons
output$clip <- renderUI({
rclipButton(
inputId = "clipbtn",
label = "rclipButton Copy",
clipText = input$aceEdId,
icon = icon("clipboard"),
tooltip = "Click me to copy the content of the text field to the clipboard!",
options = list(delay = list(show = 800, hide = 100), trigger = "hover"),
modal = TRUE # IMPORTANT!
)
})
observeEvent(input$openModal, {
showModal(modalDialog(
uiOutput("clip"),
aceEditor(
outputId = "aceEdId",
value = "some code"
)
))
})
}
shinyApp(ui, server)