【问题标题】:Creating shiny outputs from custom html inputs从自定义 html 输入创建闪亮的输出
【发布时间】:2021-10-04 22:32:18
【问题描述】:

为什么observeEvent() 在我使用tags$button 和相应的id 时没有被触发,但是当我使用actionButton 和inputId 时。区别在哪里?如何使我的自定义 html tags$button 成为实际的“事件”?

这不起作用:

library(shiny)
if (interactive()) {
  options(device.ask.default = FALSE)
  
  ui = fluidPage(
    
    tags$button(id = "action", "BTN"),
    plotOutput(outputId = "plot"))    
  
  server = function(input, output, session){
    
    observeEvent(input$action, {
      
      output$plot = renderPlot({
        hist(iris$Sepal.Length)})
    })
  }
  shinyApp(ui, server)
}

这样做:

library(shiny)
if (interactive()) {
  options(device.ask.default = FALSE)
  
  ui = fluidPage(
    
    actionButton(inputId = "action", label = "BTN"),
    plotOutput(outputId = "plot"))    
  
  server = function(input, output, session){
    
    observeEvent(input$action, {
      
      output$plot = renderPlot({
        hist(iris$Sepal.Length)})
    })
  }
  shinyApp(ui, server)
}

【问题讨论】:

    标签: r shiny shiny-reactivity


    【解决方案1】:

    如果您将操作按钮类添加到您的按钮,它会起作用

    tags$button(id = "action", "BTN", class="action-button")
    

    【讨论】:

    • 这真的很管用 :) 类“action-button”对我的按钮做了什么?
    • 它将其转换为事件监听器。您可以通过在浏览器中检查按钮的 HTML 来查看差异。
    • 我想如果我不使用这个class = 'action-button' - 解决方法,我将不得不做很多手动javascript编程,对吧?
    • 我真的不知道
    猜你喜欢
    • 2014-10-11
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    相关资源
    最近更新 更多