【发布时间】:2021-09-26 17:32:53
【问题描述】:
我正在尝试在 Shiny 中显示文本。但我还需要在显示的文本旁边添加一个按钮。
当我打开应用程序时,我可以看到纯 HTML 内容(但没有按钮)
闪亮的代码:
library(shiny)
ui <- fluidPage(
headerPanel("Example reactiveValues"),
mainPanel(
# input field
textInput("user_text", label = "Enter some text:", placeholder = "Please enter some text."),
actionButton("submit", label = "Submit"),
# display text output
textOutput("text"))
)
server <- function(input, output) {
flag_1 <- TRUE
text_reactive = reactiveValues(text = "No values are updated")
output$text <- renderText({
text_reactive$text
})
observeEvent(input$submit,{
if(flag_1 <- FALSE)
{
text_reactive$text <- input$user_text
}
else {
text_reactive$text <- paste0("hi", HTML(as.character(actionButton('id','label'))))
}
})
}
shinyApp(ui = ui, server = server)
有没有办法将 HTML 代码呈现为实际的按钮?
【问题讨论】:
-
您是否与
actionButton()shiny.rstudio.com/reference/shiny/latest/actionButton.html 核对过?此链接也可能有助于将其内联community.rstudio.com/t/… -
否 基本上我需要在服务器中。为了逃避,我可以在 Dt 表中粘贴一个按钮,声明
escape = false。但是在一行中,我如何粘贴一个按钮?希望你明白我的意思:) -
actionButton('id','label')返回<button id="id" type="button" class="btn btn-default action-button">label</button>。你可以喂这个结构。 -
我这样做了,但是当我打开应用程序时,我收到了
hi<button id="id" type="button" class="btn btn-default action-button">label</button> -
你试过用
HTML()包装它吗?