我有一个小的Shiny应用程序,可以使用insertUI随机化演讲者的列表(以防有更多(。
问题是,我只使用textInput来完成它,而在没有输入框的情况下,我无法完成它——只是为了显示没有框的文本。这更像是一件美学的事情,但在经历了几个小时的失败试验后,我在这里寻求帮助。
我真的很感激你的帮助
Herunia
这是代码:
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)
}
这更接近您想要的吗?
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)