简体   繁体   English

如何使用 insertUIs 在 Shiny 应用程序中将 textInput 转换为 output

[英]How to convert textInput to output in the Shiny appplication with insertUIs

I have a small Shiny app to randomize speaker's list using insertUI (in case there is be more of them).我有一个小的 Shiny 应用程序来使用 insertUI 随机化扬声器列表(以防它们更多)。

The problem is that I only got it working using textInput and I fail to get it done without the input box - just to display the text without the box.问题是我只使用textInput让它工作,没有输入框我无法完成它 - 只是为了显示没有输入框的文本。 It's more of an aesthetics thing but after many hours of unsuccessful trials I'm reaching out for help here.这更像是一种美学问题,但经过数小时不成功的试验后,我在这里寻求帮助。

I really appreciate your help.我真的很感谢你的帮助。
Herunia赫鲁尼亚

Here is the code:这是代码:

if (interactive()) {
       
  ui <- fluidPage(      
    actionButton("add", "Next speaker")
         )
  
  # Server logic
  server <- function(input, output, session) {
    a <- sample(c("Speaker 1","Speaker 2","Speaker 3","Speaker 4","Speaker 5"))
    uiCount = reactiveVal(0)
    observeEvent(input$add, {
      
      uiCount(uiCount()+1)
      insertUI(
        selector = "#add",
        where = "afterEnd",
        ui = textInput(paste0("txt", input$add), paste0("Speaker #", uiCount() , ": "),
                       placeholder = a[uiCount()] ), 
      )
    })
  }
  shinyApp(ui, server)
}

Is this closer to what you want?这更接近你想要的吗?

ui <- fluidPage(
  actionButton("add", "Next speaker"),
  uiOutput("txt")
)

server <-  function(input, output, session) {
  a <- sample(c("Speaker 1","Speaker 2","Speaker 3","Speaker 4","Speaker 5"))
  uiCount = reactiveVal(0)
  
  observeEvent(input$add, {
    uiCount(uiCount()+1)
    
    output$txt <- renderUI({
      div(
        p(
          paste0("Speaker #", uiCount(), " :", a[uiCount()])
        ) #close p
      ) #close div
    })
  })
}
shinyApp(ui, server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM