【发布时间】:2018-10-18 18:19:04
【问题描述】:
到目前为止,我选择了包含文档名称的数据表的一行,并从数据库中获取有关所选文档的信息。此信息的概述在另一个选项卡中。现在,我喜欢有一个按钮“下一步”来选择选中后的行,以显示下一个文档的信息。我不能使用 rownumber+1 因为我的数据表是有序的。有没有办法使用按钮在我选择的行之后获取行?
更新:
library(DT)
# ui
ui <- tagList(
ui <- basicPage(
h2("My Table"),
DT::dataTableOutput("DT_show_docs"),
textOutput("printScore"),
actionButton("next_doc", "Next Document")
)
)
# Server
server <- function(input, output, session) {
doc_overview <- reactive({
df <- data.frame(Doc_ID = seq(1,100), Filename = paste0("File_",seq(1,100)), Score = sample(1:10,100,replace=TRUE), Approved = rep(c("No", "Yes"), times = c(95,5)), Date = rep(seq(as.Date("2018/01/01"), as.Date("2018/1/10"), "days"), length.out=100))
return(df)
})
output$DT_show_docs <- renderDataTable({
DT::datatable(doc_overview(),
options = list(
searching = FALSE,
order = list(list(3, 'desc'))),
selection = "single")
})
output$printScore <- renderText({
row <- input$DT_show_docs_rows_selected
text <- doc_overview()[row, "Filename"]
})
observeEvent(input$next_doc, {
# Function to select next row/document from datatable. When the button is clicked,
# and the first row is selected at this moment, I want to select/print the second
# row and so on.
})
}
# app
shinyApp(ui = ui, server = server)
【问题讨论】:
-
我可以帮助你,但我需要你提供一个绝对最小但完全可重现的应用程序代码。请更新您的问题,我会回答。
-
我添加了一个最小且完整的应用程序代码。提前谢谢!!!