【发布时间】:2021-06-01 03:00:51
【问题描述】:
我在 Shiny 应用程序中使用了一些 JavaScript 代码,以便在模式中设置 textAreaInput 的样式。我的代码如下所示:
library(shiny)
codeJS <- "
document.addEventListener('DOMContentLoaded', function(event)
{
function init (inputID)
{
var text = document.getElementById(inputID);
text.style.color = 'blue';
};
init('textField');
})"
ui <- fluidPage(
tags$script(HTML(codeJS)),
actionButton(inputId="openModal", label="Open modal")
)
server <- function(input, output, session)
{
observeEvent(input$openModal,
{
showModal(modalDialog(
textAreaInput(inputId = "textField", label = "window", value = "ABC")
))
})
}
shinyApp(ui, server)
当textAreaInput(inputId = "textField", label = "window", value = "ABC") 放在模态框之外时,JavaScript 代码可以正常工作。但是 JavaScript 代码对模态框内的输入没有影响。
有什么解决办法吗?
【问题讨论】:
标签: javascript r shiny shinyjs