问题描述
我想在ShinyApp中使用HTML创建一个按钮。原因是根据用户的输入,我有时想创建十个按钮,有时不创建任何按钮。
如果仅编写<button id="popup" type="button" class="btn btn-default action-button">Click me</button>
并进行渲染,则会得到一个不起作用的按钮。
示例:
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),actionButton("popup","This button works"),htmlOutput("ButtonText"),htmlOutput("jsButton")
)
server <- function(input,output) {
runjs("document.getElementById('popup2').onclick = function() {
window.open('http://stackoverflow.com/','_blank');};"
)
output$ButtonText <- renderText({
'<button id="popup" type="button" class="btn btn-default action-button shiny-bound-input">This button does not</button>'
})
output$jsButton <- renderText({
'<button id="popup2" type="button" class="btn btn-default action-button">Neither does this one</button>'
})
observeEvent(input$popup,{
showModal(modalDialog(
title = "Pop-up","It worked!",easyClose = TRUE,footer = tagList(
modalButton("Close"))
))
})
}
shinyApp(ui = ui,server = server)
您可以看到我也尝试使用Javascript调用操作,但没有成功。
<button id="popup" type="button" class="btn btn-default action-button shiny-bound-input">This button works</button>
<div id="ButtonText" class="shiny-html-output shiny-bound-output">
<button id="popup" type="button" class="btn btn-default action-button shiny-bound-input">This button does not</button>
</div>
也许包括class =“ shiny-bound-output”的div使得内容无法调用。有什么办法可以使按钮起作用?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)