【发布时间】:2021-07-07 15:50:45
【问题描述】:
在下面的 Shiny 应用程序代码中,我希望在用户单击数据表中的新行时执行打印行。当我这样做时, textOutput 会按预期通过 input$table_rows_selected 更新所选行。但是为什么 change
我看到它可以与 observe({}) 一起使用,但最终我想使用一个在不同位置响应式返回的值(例如这里的 return 和 return2)。
library(shiny)
library(DT)
ui <- fluidPage(
DT::DTOutput("table"),
textOutput("selected"),
textOutput("return"),
textOutput("return2")
)
server <- function(input, output) {
output$table <- DT::renderDataTable({
data.frame(a = 1:3, b = 4:6)
}, selection = 'single')
output$selected <- renderText({
input$table_rows_selected
})
change <- reactive({
input$table_rows_selected
print("it changed!")
"return"
})
output$return <- renderText({
isolate(change())
})
output$return2 <- renderText({
paste0(isolate(change()), "_2")
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny datatables