在应用程序中有两个操作按钮,“tasto.a”和“tasto.b”,如果我按“key.a”按钮,则数据框“a”被分配给 tab.SDO(),如果我按“key.a”按钮 data.frame“a”被分配给 tab.SDO(),以便在 ui 中呈现所选的 data.frame。问题是只进行了列表中的第二个分配(tab.SDO <- eventReactive (input $ key.b, {b})) even if I press the "key.b" key. Is this type of "conditional" assignment correct or am I making some mistakes?
require(shiny)
a <- data.frame(a.x = c(1,3,4,5,1,2), a.y = c("A", "A", "B", "B", "C", "C"))
b <- data.frame(b.x = c(21,33,44,52,13,27), b.y = c("D", "D", "E", "E", "F", "F"))
#### UI ####
ui <- navbarPage(title = "FLUSSI SANITARI",
theme = shinytheme("cerulean"),
#### Schede di dimissione ospedaliera ####
tabPanel(title = "prova",
sidebarLayout(
sidebarPanel(
actionButton("tasto.a", "a"),
actionButton("tasto.b", "b")
),
mainPanel(
div(DT::dataTableOutput("tabella.SDO"), style = "font-size:80%")
)
)
)
)
#### SERVER ####
server <- function(input, output, session) {
tab.SDO <- eventReactive(input$tasto.a, {a})
tab.SDO <- eventReactive(input$tasto.b, {b})
output$tabella.SDO <- DT::renderDataTable({tab.SDO()}, rownames = FALSE,
options = list(pageLength = 25)
)
}
# Run the application
shinyApp(ui = ui, server = server)
您可以使用无功值和一些
observeEvent
:
server <- function(input, output, session) {
tab.SDO <- reactiveVal(a)
observeEvent(input$tasto.a, {
tab.SDO(a)
})
observeEvent(input$tasto.b, {
tab.SDO(b)
})
output$tabella.SDO <- DT::renderDataTable({tab.SDO()}, rownames = FALSE,
options = list(pageLength = 25)
)
}