【问题标题】:Perform multiple actions on actioButton Shiny在 actionButton Shiny 上执行多项操作
【发布时间】:2017-01-23 05:59:49
【问题描述】:

我对 Shiny 很陌生,并且正在处理以下问题,在按下闪亮的 actionButton 时,我希望它进行多次计算。我使用observeEvent的处理程序。

一个例子:

library(shiny)
ui <- fluidPage(
  sidebarLayout(
  sidebarPanel(`

     actionButton("calc","calculate stuff")),
  mainPanel(
     textOutput("result")
 )
)
)


server <- function(input,output){
  observeEvent(input$calc, {output$result <- renderText({"only this is not enough"})  })
}


shinyApp(ui,server')`

现在我想要的是在 server-observeEvent 中生成 output$result 的位置,我想执行其他任务,比如分配一个变量 a

我想这并不难..但我只是没有到达那里。

亲切的问候,

彼得

【问题讨论】:

    标签: r events shiny action-button


    【解决方案1】:

    你可以使用isolate,看这个例子:

    library(shiny) 
    ui <- fluidPage(
      sidebarLayout(
        sidebarPanel( 
          numericInput(inputId = 'x', label = 'Select a value for x', value = 1),
          actionButton(  "calc", "calculate stuff" )  
        ),
        mainPanel(
          textOutput("result")
        )
      )
    ) 
    
    server <- function(input, output) {   
      output$result <- renderText({
        input$calc 
        isolate({
          y<- input$x *2 
          paste("The result is:", y) 
        }) 
      }) 
    }  
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢@(Ron Talbot)。我发现使用例如 observe() 也可以轻松执行更多任务。你知道什么是更高效/更适合的编程吗?
    猜你喜欢
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 2021-07-17
    • 2016-09-15
    • 2020-04-11
    • 2021-07-28
    • 2020-11-14
    • 2019-01-20
    相关资源
    最近更新 更多