r - 仅在单击 Shiny 中的操作按钮后才更新服务器上的内容

标签 r shiny plotly

我在 R 中 Shiny 的服务器中遇到 react 输出问题。

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

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

我设法做的是独立于提交按钮更新内容(提交按钮根本没有功能),并且在我更改 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"
    )
   )
  )
 )

这是 server.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/

Tab 被称为 Minimal_Example

谢谢

最佳答案

submitButton就是为此而生的。

如果您想使用 actionButton相反,只需使用 isolate避免根据值更改刷新,并添加 input$Button在代码中,如:

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

关于r - 仅在单击 Shiny 中的操作按钮后才更新服务器上的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44251872/

相关文章:

r - 如何在R中执行近似(模糊)名称匹配

R函数不返回值

r - 使用 r 找到双峰分布中的局部最小值

r - 将图像添加到 Shiny 的应用程序

python - 如何修复 ImportError : cannot import name 'Event' in Dash from plotly (python)?

python - 使用 plotly 的动态频谱

r - Sweave,R,Beamer : How to convert the LaTex text in an Rnw file to R comments?

r - Shiny 问题 - 跟踪多用户环境中的用户设置

javascript - 如何预选 Shiny DT 数据表中的行

python - 如何使用绘图等值线根据百分比更改颜色,美国 map ?