【问题标题】:Add a button next to statement in shiny在闪亮的语句旁边添加一个按钮
【发布时间】: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') 返回&lt;button id="id" type="button" class="btn btn-default action-button"&gt;label&lt;/button&gt;。你可以喂这个结构。
  • 我这样做了,但是当我打开应用程序时,我收到了hi&lt;button id="id" type="button" class="btn btn-default action-button"&gt;label&lt;/button&gt;
  • 你试过用HTML()包装它吗?

标签: r shiny


【解决方案1】:

下面的呢?

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
    uiOutput("text"))
)

server <- function(input, output) {
  
  flag_1 <- TRUE
  
  text_reactive = reactiveValues(text = "No values are updated")
  
  output$text <- renderUI({
    HTML(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',input$user_text))))
    }
  })
}

shinyApp(ui = ui, server = server)

【讨论】:

  • 嘿,一个问题。但我无法触发它。例如,我需要在点击按钮后弹出模态框。我们能做到吗?
猜你喜欢
  • 2013-09-16
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-22
  • 2019-12-20
  • 2016-03-21
相关资源
最近更新 更多