我试图捕获当人们按下应用程序上的“获取 URL”按钮时所选择的 URL。
应该发生的是event reactive()
应该看看input$go_button
并看到它已被按下 - 然后它应该执行表达式以从选择输入中获取所选的 url - 不幸的是它什么也没做。
我尝试过使用 browser() 进行调试,但仍然没有效果。
我想做的就是捕获当一个人“按下”“获取 URL”按钮时所选择的 URL。
我的示例代码如下:
library(shiny)
# Use a fluid Bootstrap layout
ui <- fluidPage(
# Give the page a title
titlePanel("testing select"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("url_selection", "select url:",
choices = c(
'/multi-task/',
"/personal-account",
"/paperless"
)
),
actionButton(inputId = "go_button", label = "Get URLS")
),
# Create a spot for the barplot
mainPanel(
textOutput(outputId = "urls_selected_print")
)
)
)
server <- function(input, output) {
url_capture <- reactive({eventReactive(eventExpr = input$go_button,
valueExpr = {
message("capturing url chosen in selectize input")
chosen_url <- input$url_selection
browser()
return(chosen_url)
})
})
}
shinyApp(ui, server)
您可以使用observeEvent
捕获事件时go_button
已被按下。您可以将选择存储在reactiveVal
可以显示在您的输出中。
server <- function(input, output) {
rv <- reactiveVal(NULL)
observeEvent(input$go_button, {
message("capturing url chosen in selectize input")
rv(input$url_selection)
})
output$urls_selected_print <- renderText({rv()})
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)