Can I have multiple submit buttons in R shiny?

故事扮演 提交于 2020-01-06 02:47:07

问题


In my R shiny application, I would like to have one button to submit one set of inputs (which affect one portion of the output) and another one to submit the remaining inputs (which affect a different portion of the output). The code in the widgets example of the Shiny tutorial uses a submitButton but it seems like all the inputs are delivered when that single button is pressed? Thanks in advance for your help.


回答1:


Here is an example showing actionButtons controlling reactive components:

library(shiny)
runApp(list(
  ui = fluidPage(
    titlePanel("Hello Shiny!"),
    sidebarLayout(
      sidebarPanel(
        tags$form(
          numericInput('n', 'Number of obs', 100)
          , br()
          , actionButton("button1", "Action 1")
        )
        , tags$form(
          textInput("text", "enter some text", value= "some text")
          , br()
          , actionButton("button2", "Action 2")
        )
      ),
      mainPanel(
        plotOutput('plot')
        , textOutput("stext")
      )
    )
  ),
  server = function(input, output) {
    output$plot <- renderPlot({ 
      input$button1
      hist(runif(isolate(input$n))) 
    })
    output$stext <- renderText({
      input$button2
      isolate(input$text )
    })
  }
)
)



来源:https://stackoverflow.com/questions/24220105/can-i-have-multiple-submit-buttons-in-r-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!