html text 默认选中,html - 如何在Shiny中默认选择verbatimTextOutput中的文本? - SO中文参考 - www.soinside.com...

感谢@ismirsehregal的帮助。在这里,我分享了这个问题的解决方法。此答案在只读模式下使用textAreaInput,而不是我最初要求的verbatimTextOutput。但是,我对textAreaInput的结果和最终外观感到满意。library(shiny)

ui

fluidPage(

column(

width = 6,

tags$head(

tags$script("

Shiny.addCustomMessageHandler('selectText', function(message) {

$('#txt_out').select();

$('#txt_out').prop('readonly', true);

});

")

),

textInput(inputId = "txt", label = "Type in some texts",

value = paste0(rep(letters, 10), collapse = "")),

textAreaInput("txt_out", label = "Show the texts", heigh = "300px"),

br(),

bookmarkButton()

)

)

}

server

observeEvent(input$txt, {

updateTextAreaInput(session = session, inputId = "txt_out", value = input$txt)

})

observeEvent(input$txt_out, {

session$sendCustomMessage("selectText", "select")

})

}

enableBookmarking("url")

shinyApp(ui, server)

这是应用程序运行时的外观。

eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS92ZTZ5Mi5wbmcifQ==


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部