JavaScript在模式中不工作
我在一个闪亮的应用程序中使用了一些JavaScript代码,以便在模式中设置textAreaInput的样式。我的代码如下所示:JavaScript在模式中不工作,javascript,shiny,modal-dialog,bootstrap-modal,shinyjs,Javascript,Shiny,Modal Dialog,Bootstrap Modal,Shinyjs,我在一个闪亮的应用程序中使用了一些JavaScript代码,以便在模式中设置textAreaInput的样式。我的代码如下所示: library(shiny) codeJS <- " document.addEventListener('DOMContentLoaded', function(event) { function init (inputID) { var text = document.getE
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)
codeJS <- "
function init (inputID)
{
var text = document.getElementById(inputID);
text.style.color = 'red';
text.style.fontSize = '20px';
text.style.fontStyle = 'italic';
};
init('textField');"
ui <- fluidPage(
actionButton(inputId="openModal", label="Open modal")
)
server <- function(input, output, session)
{
observeEvent(input$openModal,
{
showModal(modalDialog(
textAreaInput(inputId = "textField", label = "window", value = "ABC"),
tags$script(HTML(codeJS))
))
})
}
shinyApp(ui, server)
库(闪亮)
codeJS您可以将CSS代码内联,如下所示
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"),
tags$head(tags$style("#textField{color: red;
font-size: 20px;
font-style: italic;
}" ))
))
})
}
shinyApp(ui, server)
ui您可以将CSS代码内联,如下所示
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"),
tags$head(tags$style("#textField{color: red;
font-size: 20px;
font-style: italic;
}" ))
))
})
}
shinyApp(ui, server)
uiYBS让我走上了正确的轨道。使用JavaScript而不是CSS时,代码如下所示:
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)
codeJS <- "
function init (inputID)
{
var text = document.getElementById(inputID);
text.style.color = 'red';
text.style.fontSize = '20px';
text.style.fontStyle = 'italic';
};
init('textField');"
ui <- fluidPage(
actionButton(inputId="openModal", label="Open modal")
)
server <- function(input, output, session)
{
observeEvent(input$openModal,
{
showModal(modalDialog(
textAreaInput(inputId = "textField", label = "window", value = "ABC"),
tags$script(HTML(codeJS))
))
})
}
shinyApp(ui, server)
codeJSYBS让我走上了正轨。使用JavaScript而不是CSS时,代码如下所示:
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)
codeJS <- "
function init (inputID)
{
var text = document.getElementById(inputID);
text.style.color = 'red';
text.style.fontSize = '20px';
text.style.fontStyle = 'italic';
};
init('textField');"
ui <- fluidPage(
actionButton(inputId="openModal", label="Open modal")
)
server <- function(input, output, session)
{
observeEvent(input$openModal,
{
showModal(modalDialog(
textAreaInput(inputId = "textField", label = "window", value = "ABC"),
tags$script(HTML(codeJS))
))
})
}
shinyApp(ui, server)
你把我带到了正确的轨道上。但是我想用JavaScript而不是CSS。你让我走上了正确的道路。但是我想用JavaScript而不是CSS。你能告诉我在运行脚本时出了什么问题吗?你的答案很好。很抱歉,我没有复制新的codeJS脚本,因为我认为您原来的codeJS没有更改。您能告诉我运行脚本时出现了什么问题吗?您的答案很好。很抱歉,我没有复制新的codeJS脚本,因为我认为您原来的codeJS没有更改。