我正在尝试捕获有人在应用程序上按下“获取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()})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句