仅在单击Shiny中的“操作"按钮后才更新服务器上的内容 [英] Update content on server only after I click action button in Shiny

查看:99
本文介绍了仅在单击Shiny中的“操作"按钮后才更新服务器上的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在R的闪亮服务器中无功输出有问题.

我想做的是创建一个使用基于输入计算的值的绘图.

仅在单击提交/完成"按钮后才需要更新输出,并且必须根据需要多次计算输出.

我要做的就是独立于提交按钮(提交按钮根本没有任何功能)来更新内容,并且在更改1值后立即更改了图.

我想做的是仅在指定了所需参数的所有值之后才更改图.

这是我的ui.R代码的一个最小示例:

    shinyUI(fluidPage(
      titlePanel("Wages in Year 2016 for Czech Republic in CZK"),
       sidebarPanel(

      conditionalPanel(condition = "input.conditionedPanels==7",
                 selectInput("Age", "Age", choices = vek_mod$Vek, selected = "23-27"),
                 selectInput("ChosenSex", "Your sex", choices = pohlavi_mod$Pohlavie, selected = "Zena"),
                 actionButton("Button", "Done"),
                 p("Click so changes will take effect.")
      ),
        mainPanel(
         tabsetPanel(
           ...
            tabPanel("Minimal_Example", textOutput("Minimal_Example"), value = 7)
            ...
            , id = "conditionedPanels"
    )
   )
  )
 )

这是服务器R代码:

...
  output$Minimal_Example <- renderPrint({

    Age <- input$Age
    Sex <- input$ChosenSex
    c(Age, Sex)
    })
...

我使用observeEvent()和eventReactive()尝试了很多事情,但是到目前为止,对我来说没有任何作用.

如果要查看代码的行为,请看此处: http://52.59.160.3:3838/sample-apps/Mzdy_ShinyApp/

标签称为Minimal_Example

谢谢

解决方案

submitButton就是为此而制作的.


如果要使用actionButton代替,只需使用isolate即可避免基于值更改进行刷新,并在类似以下代码的代码中添加input$Button:

output$Minimal_Example <- renderPrint({
  input$Button
  Age <- isolate(input$Age)
  Sex <- isolate(input$ChosenSex)
  c(Age, Sex)
}) 

I'm having problems with reactive output in shiny server in R.

What I want to do is create a plotly plot that uses values calculated based on input.

The output has to be updated only after I click submit/done button and the output has to be calculated as many times as needed.

What I managed to do was to update the content independently of the submit button (the submit button simply has no function) and the plot changed immediately after I changed 1 value.

What I would like to do is to change the plot only after I specify all the values of parameters I want.

Here is a minimal example of my ui.R code:

    shinyUI(fluidPage(
      titlePanel("Wages in Year 2016 for Czech Republic in CZK"),
       sidebarPanel(

      conditionalPanel(condition = "input.conditionedPanels==7",
                 selectInput("Age", "Age", choices = vek_mod$Vek, selected = "23-27"),
                 selectInput("ChosenSex", "Your sex", choices = pohlavi_mod$Pohlavie, selected = "Zena"),
                 actionButton("Button", "Done"),
                 p("Click so changes will take effect.")
      ),
        mainPanel(
         tabsetPanel(
           ...
            tabPanel("Minimal_Example", textOutput("Minimal_Example"), value = 7)
            ...
            , id = "conditionedPanels"
    )
   )
  )
 )

and here is the server.R code:

...
  output$Minimal_Example <- renderPrint({

    Age <- input$Age
    Sex <- input$ChosenSex
    c(Age, Sex)
    })
...

I tried a lot of things with observeEvent() as well as eventReactive() but so far nothing has worked for me.

If you want to see how the code behaves like, look here: http://52.59.160.3:3838/sample-apps/Mzdy_ShinyApp/

Tab is called Minimal_Example

Thanks

解决方案

submitButton is just made for this.


If you want to use actionButton instead, simply use isolate to avoid refresh based on value changes, and add the input$Buttonin the code like:

output$Minimal_Example <- renderPrint({
  input$Button
  Age <- isolate(input$Age)
  Sex <- isolate(input$ChosenSex)
  c(Age, Sex)
}) 

这篇关于仅在单击Shiny中的“操作"按钮后才更新服务器上的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆