首页 > 解决方案 > 在 R Shiny 中通过 bsbutton 插入 UI。单击按钮时,UI 不会插入。请问有什么帮助吗?

问题描述

我正在尝试创建一个交互式 UI,它在用户与其交互时要求提供更多详细信息。我添加了一个 bsButton,它应该插入更多输入选项以收集更多详细信息,但是单击该按钮时不会插入 UI。对代码有任何帮助或建议吗?提前致谢。

ui <- shinyUI(  #UI
  dashboardPage( 
       fluidPage(  
         fluidRow(
            introBox(
                bsButton("pricing_request", #button to insert UI to collect more details
                         label = "Pricing Request", 
                         icon = icon("car-battery"), 
                         style = "success")
)))))

#serverpart

server <- function(input, output, session) {


observeEvent(input$pricing_request,{
insertUI(
selector = "#add",
where = "afterEnd",
ui = box(               #UI to be inserted
  bootstrapPage(
    div(style="float:right", actionButton("add_request", 
                                          label = "add option", 
                                          icon = icon("plus"), 
                                          style = "arial")),
    
    div(style="display:inline-block",
        textInput(
          inputId = "option_1",
          label = "Option",
          width = '350px',
          value = "insert option"))))
 )})}




             
    
       

标签: rshinyrenderui

解决方案


通过写作

insertUI(
  selector = "#add",
  where = "afterEnd",
  ......

您请求在 id 为 .html 的 HTML 元素之后添加一个 UI add。但是您的应用程序中没有这样的元素。如果您div(id = "add")在应用程序中添加某个位置,那应该可以。


推荐阅读