我在 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/