【问题标题】:How to convert textInput to output in the Shiny appplication with insertUIs如何使用 insertUI 在 Shiny 应用程序中将 textInput 转换为输出
【发布时间】:2021-04-17 18:39:55
【问题描述】:

我有一个小的 Shiny 应用程序可以使用 insertUI 随机化扬声器列表(以防它们更多)。

问题是我只使用 textInput 让它工作,并且在没有输入框的情况下无法完成它 - 只是在没有输入框的情况下显示文本。 这更像是一种美学问题,但经过数小时不成功的试验后,我在这里寻求帮助。

非常感谢您的帮助。
赫鲁尼亚

代码如下:

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)
}

【问题讨论】:

  • 你试过?textOutput吗?
  • 我试过了,但我无法让它工作......

标签: r shiny textinput


【解决方案1】:

这更接近你想要的吗?

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)

【讨论】:

  • 是的,这太棒了 - 非常感谢您的帮助!
猜你喜欢
  • 2019-12-15
  • 2018-02-28
  • 2022-08-04
  • 2021-07-25
  • 2021-10-16
  • 2021-06-28
  • 2017-05-11
  • 2015-01-26
  • 2018-03-10
相关资源
最近更新 更多