r - 如何将两个 actionButton 与两个单独的闪亮观察事件一起使用?
问题描述
我仍然有更新的问题,如如何在闪亮的 eventReactive 处理程序中侦听多个事件表达式中所述。
有两个单独的 actionButton 响应不同的 observeEvent。来自 observeEvent 的值将被发送到 UI。
虽然我尝试了上述方法,但仍然有很多错误。这两个 actionButton 不能独立运行。
例如:
#rm(list = ls())
library(shiny)
ui <- shinyUI(bootstrapPage(
column(12,align="center", div(textOutput('txfg'),style = "font-size:18px")),
br(),
actionButton("test1", "test1"),
actionButton("test2", "test2"))
)
server <- shinyServer(function(input, output) {
toListen <- reactive({
list(input$test1,input$test2)
})
observeEvent(toListen(), {
################## two different observeEvent
if(input$test1==0 && input$test2==0){
return()
}
if(input$test1==1)
{ outputTest <- 'Hello World'}
if(input$test2==1)
{ outputTest <-'World Hello'}
})
##################
output$txfg <- renderText(outputTest)
})
shinyApp(ui, server)
解决方案
我目前也在研究 Shiny,看来最佳实践是为您的服务器和 ui 元素构建模块。让我重写(并评论)您的服务器部分:
server <- shinyServer(function(input, output) {
observeEvent({input$test1: input$test2}, {
output$Test <- ifelse(input$test1 == 0, NULL,
ifelse(input$test1 == 1, "Hello World", NULL))
output$Test <- ifelse(input$test2 == 0, NULL,
ifelse(input$test2 == 1, "Hello World", NULL))
})
output$txfg <- renderText(output$Test)
}
推荐阅读
- c# - c# 从服务启动应用程序
- system-verilog - verilog中的映射错误
- python - E1101:模块 'cv2' 没有 'copyMakeBorder' 成员
- ruby-on-rails - 带有 Redcarpet 的 Rails 无法呈现表格并且无法链接目标
- reactjs - React-Apollo Query 组件变量永远不会更新
- django - 将 Postgres 原始查询转换为 Django Orm 查询
- python - flask route 函数将“None”注入 url 并发出两个 GET 请求
- reactjs - 无法访问道具中的“历史”
- php - 使用 nuovo/spreadsheet-reader lib 在 php 中读取 xls 文件
- python - 加载单词向量时在python中解开堆栈下溢