0
我寫的小例子一個按鈕的意外點擊
library(shiny)
ui <- fluidPage(
fluidRow(
wellPanel(radioButtons(inputId = "radio1", label="Radio 1", choices = c("Yes", "No"), selected = "No"),
actionButton("btnClick1", "Click 1"))
),
fluidRow(
wellPanel(radioButtons(inputId = "radio2", label="Radio 2", choices = c("Yes", "No"), selected = "No"),
actionButton("btnClick2", "Click 2"))
),
fluidRow(
wellPanel(radioButtons(inputId = "radio3", label="Radio 3", choices = c("Yes", "No"), selected = "No"),
actionButton("btnClick3", "Click 3"))
)
)
options(shiny.reactlog=TRUE)
server <-function(input, output, session) {
values <- reactiveValues(radio1 = FALSE, radio2 = FALSE, radio3 = FALSE)
observe(
if (input$btnClick1)
{
if (values$radio1 == TRUE)
{
isolate({cat("input$btnClick1 ", input$btnClick1, "\n")});
}
}
);
observeEvent(input$radio1, {
print("observeEvent input$radio1");
if (input$radio1 == "Yes") {
print("Yes");
values$radio1 = TRUE;
} else {
print("No");
values$radio1 = FALSE;
}
});
observe(
if (input$btnClick2)
{
if (values$radio2 == TRUE)
{
isolate({cat("input$btnClick2 ", input$btnClick2, "\n")});
}
}
);
observeEvent(input$radio2, {
print("observeEvent input$radio2");
if (input$radio2 == "Yes") {
print("Yes");
values$radio2 = TRUE;
} else {
print("No");
values$radio2 = FALSE;
}
freezeReactiveValue(values, "radio2")
});
observeEvent(input$btnClick3, {
req(values$radio3 == TRUE);
isolate({cat("input$btnClick3 ", input$btnClick3, "\n")});
});
observeEvent(input$radio3, {
print("observeEvent input$radio3");
if (input$radio3 == "Yes") {
print("Yes");
values$radio3 = TRUE;
} else {
print("No");
values$radio3 = FALSE;
}
});
}
shinyApp(ui = ui, server = server)
https://gist.github.com/bezany/d9380a1e80b213dcd795f605355912bd 在RStudio運行例如:runGist("d9380a1e80b213dcd795f605355912bd")
如果點擊「按1」,並設置「無線電1」到「是」看到手柄「輸入$ btnClick1」。爲什麼會發生? 當「Radio 1」設置爲「Yes」時,「input $ btnClick1」中的當前點擊數觸發了此操作?如何閃亮記住點擊處理?
您應該在此處提供您的代碼,而不是指向外部網頁的鏈接。 – Masoud
編輯。粘貼代碼在這裏 – bezanyu