【问题标题】:Shiny: access input object from own JS scriptShiny:从自己的 JS 脚本访问输入对象
【发布时间】:2019-01-20 22:31:50
【问题描述】:

condition arg 中的 Shiny conditionalPanel 中,可以访问 JS input 对象,因此如果有 numericInput("num", label = h3("Numeric input"), value = 1) 小部件,则此小部件的值可以在 condition JS 表达式中通过 @ 访问987654326@.

问题是如何以同样的方式访问自己的 JS 脚本中的input 对象(在 Shiny 应用程序中启动)或仅从 Shiny 应用程序页面上打开的浏览器控制台访问?

【问题讨论】:

    标签: javascript r shiny


    【解决方案1】:

    最好的方法可能是收听shiny:inputchanged events

    library(shiny)
    
    shinyApp(
      ui = fluidPage(
        tags$head(tags$script("
          $(document).on('shiny:inputchanged', function(event) {
            console.log(event);
            console.log('[input] ' + event.name + ': ' + event.value);
          });
        ")),
        numericInput("num", "", 0, 0, 5),
        textInput("txt", ""),
        actionButton("action", "Action")
      ),
      server = function(input, output) {}
    )
    

    您还可以使用 session$sendCustomMessageShiny.addCustomMessageHandler 从服务器发送输入值。


    一种未记录的、更不推荐的方法是直接通过Shiny.shinyapp.$inputValues 访问输入值,这是一个在name:type 键下存储值的对象:

    {
      "action:shiny.action": 4,
      "num:shiny.number": 2,
      "txt": "text"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 2020-09-13
      • 1970-01-01
      • 1970-01-01
      • 2015-03-05
      • 1970-01-01
      相关资源
      最近更新 更多