【问题标题】:shiny Change data input of buttons闪亮的改变按钮的数据输入
【发布时间】:2013-09-19 22:23:24
【问题描述】:

我有一个带有活动按钮的表单,问题是我想重置此表单中的按钮output$exampleFasta = 0 但它抛出异常,我该如何更改变量的数据?或者如果存在诸如 renderImage 之类的东西,可以为特定属性(如 id)提供信息。

index.html

<form class="span12 menu-med-upload">
  <div class="row-fluid">
   <h3>Upload File .fasta</h3>
   <div class="custom-input-file btn btn-inverse">
    <input type="file" size="1" name="fileFasta" id="fileFasta" class="input-file" />
    Select File
   </div>
   <img src="/static/img/check.png" class = "custom-input-check">
   <div class="span12"></div>
   <textarea class = "span12" rows  = "10" style="resize: none;" id="textAreaFasta">
   </textarea>
 </div>
 <button id="uploadFasta" type="button" class="btn btn-inverse action-button" >Upload  File</button>
 <button id="exampleFasta" type="button" class="btn btn-inverse action-button" >Example</button>
</form>

服务器.R

output$table <- renderText({
  if(input$exampleFasta != 0 && input$uploadFasta == 0){
    return(myRenderTable(matrixProteinExample(),"table",""))
  }
  if(input$uploadFasta != 0){
    return(myRenderTable(matrixProtein(),"table",nameFile))   
  }
})

用这样的东西改变。但这是错误的。

output$table <- renderText({
  if(input$exampleFasta != 0 && input$uploadFasta == 0){
    output$exampleFasta <- 0
    return(myRenderTable(matrixProteinExample(),"table",""))
  }
  if(input$uploadFasta != 0){
    return(myRenderTable(matrixProtein(),"table",nameFile))   
  }
})

【问题讨论】:

    标签: r shiny shiny-server


    【解决方案1】:

    如果您询问如何判断最近单击了哪个 actionButton(如果有的话!),那么重置为 0 并不是解决问题的方法。而是这样做:

    shinyServer(function(input, output, session) {
    
      # Create a reactiveValues object, to let us use settable reactive values
      values <- reactiveValues()
      # To start out, lastAction == NULL, meaning nothing clicked yet
      values$lastAction <- NULL
      # An observe block for each button, to record that the action happened
      observe({
        if (input$exampleFasta != 0) {
          values$lastAction <- 'example'
        }
      })
      observe({
        if (input$uploadFasta != 0) {
          values$lastAction <- 'upload'
        })
      })
    
      # Then you can use values$lastAction in reactive expressions, outputs, etc.
      output$table <- renderText({
        if (is.null(values$lastAction))
          return(NULL)
        if (identical(values$lastAction, 'upload'))
          return(myRenderTable(matrixProtein(), "table", nameFile))
        if (identical(values$lastAction, 'example'))
          return(myRenderTable(matrixProteinExample(), "table", ""))
        stop("Unexpected value for lastAction: ", values$lastAction)
      })
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 2018-03-13
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 2023-03-07
      • 2021-07-11
      相关资源
      最近更新 更多