R 如何使用第二个操作按钮覆盖输出
我有一个闪亮的应用程序,当按下动作按钮时,它会将数据框写入输出。这是下面的裸体示例中的“Go”按钮。我有一个重置按钮,可以重置输入值。我想知道如何重置输出(因此当按下“重置”时,输出变为空并消失) 我试图将R 如何使用第二个操作按钮覆盖输出,r,shiny,R,Shiny,我有一个闪亮的应用程序,当按下动作按钮时,它会将数据框写入输出。这是下面的裸体示例中的“Go”按钮。我有一个重置按钮,可以重置输入值。我想知道如何重置输出(因此当按下“重置”时,输出变为空并消失) 我试图将input$goButtonReset传递给eventReactive函数(目的是在函数中使用if语句来指示哪个按钮正在进行调用),但这似乎是不可能的 非常感谢任何帮助 ui <- fluidPage(title = "Working Title", sidebarLayout(
input$goButtonReset
传递给eventReactive
函数(目的是在函数中使用if语句来指示哪个按钮正在进行调用),但这似乎是不可能的
非常感谢任何帮助
ui <- fluidPage(title = "Working Title",
sidebarLayout(
sidebarPanel(width = 6,
# *Input() functions
selectInput("Input1", label = h3("Select Input1"),
choices = list("A" = "A", NULL = "NULL"),
selected = 1),
actionButton("goButton", "Go!"),
p("Click the button to display the table"),
actionButton("goButtonReset", "Reset"),
p("Click the button to reset your inputs.")
),
mainPanel(
# *Output() functions
tableOutput("pf"))
)
)
# build the outputs here
server <- function(input, output, session) {
observeEvent(input$goButtonReset, {
updateSelectInput(session, "Input1", selected = "NULL")
})
writePF <- eventReactive(input$goButton, {
data.frame("test output")
})
output$pf <- renderTable({
writePF()
})
}
shinyApp(ui = ui, server = server)
ui您可以尝试使用reactiveValues
存储数据帧。这对我很有用:
ui <- fluidPage(title = "Working Title",
sidebarLayout(
sidebarPanel(width = 6,
# *Input() functions
selectInput("Input1", label = h3("Select Input1"),
choices = list("A" = "A", NULL = "NULL"),
selected = 1),
actionButton("goButton", "Go!"),
p("Click the button to display the table"),
actionButton("goButtonReset", "Reset"),
p("Click the button to reset your inputs.")
),
mainPanel(
# *Output() functions
tableOutput("pf"))
)
)
# build the outputs here
server <- function(input, output, session) {
df <- reactiveValues()
observeEvent(input$goButton,{
df$writePF <- data.frame("test output")
})
observeEvent(input$goButtonReset,{
df$writePF <- NULL
})
output$pf <- renderTable({
df$writePF
})
}
shinyApp(ui = ui, server = server)
ui