【发布时间】:2017-03-02 04:22:22
【问题描述】:
我有以下闪亮的应用程序:
library(shiny)
ui <- fluidPage(
titlePanel("Datatable for dynamic text selection"),
sidebarLayout(
sidebarPanel(
dataTableOutput("pairs")
),
mainPanel(
strong("Sentence"), htmlOutput("content"),
strong("Selection"),textOutput("selection")
)
)
)
server <- function(input, output) {
output$content <- renderText("A sample sentence for demo purpose")
df <- data.frame(SrNo=1:5, Pairs=c("A sample", "sample sentence",
"sentence for", "for demo", "demo purpose"))
output$pairs <- renderDataTable(datatable(df, selection = "single" ))
observeEvent(input$pairs_cell_clicked,{
info = input$pairs_cell_clicked
if(is.null(info$value)) return()
output$selection <- renderText(info$value)
})
}
shinyApp(ui = ui, server = server)
应用程序在htmlOutput 中显示一个句子,在datatable 中显示相应的一对单词。目前单击数据表中的任何一对单词都会在Selection下显示它。
如何修改代码,使其不显示这对单词,而是在htmlOutput 中显示为选择?
【问题讨论】:
-
您能否详细说明您希望输出的样子?可以截图吗?
-
我自己用鼠标选择了
sample sentence,如截图所示,我希望通过在数据表中选择对来完成此选择 -
当你选择
2而不是那里的例句时会发生什么? -
如果选择了
2,则不会发生任何事情,交互仅用于选择一对单词
标签: r datatables shiny