如何 select 数据中的特定值 table
How to select the particular value in the data table
1.In 我的应用程序我只想分别显示 Ex 的每一行的数据如果我单击第一列中的任何值数据应该显示整行
就像我点击 Mazda RX4 它应该显示整行数据
2.with 扩展的帮助 = 'ColReorder' 如果我将第一列拖到其他可点击的位置,我可以将列拖到 table 中
例如,如果我将第 1(new_name) 列移到第 4 列,则可点击功能无法正常工作
任何答案将不胜感激
library(shiny)
library(DT)
data("mtcars")
ui <- shinyUI(fluidRow(
DT::dataTableOutput("myDatatable"),
verbatimTextOutput("selectedCells")
))
df <- cbind(new_name =rownames(mtcars), data.frame(mtcars, row.names= NULL))
server <- shinyServer(function(input, output, session) {
output$myDatatable <- DT::renderDataTable(
df, extensions = 'ColReorder', options = list(colReorder = TRUE),selection = list(mode = "single", target ="cell"),
server = FALSE,
rownames = T
)
output$selectedCells <- renderPrint({
s = input$myDatatable_cells_selected
if (!is.null(s) && ncol(s) != 0) {
mtcars[,1]
} else {
NULL
}
})
})
shinyApp(ui, server)
您可以通过以下方式获取所选单元格的值:
s_val = input$myDatatable_cell_clicked$value
之后,您可以在数据中搜索此值并打印整行:
df[df$new_name==s_val,]
已测试:
library(shiny)
library(DT)
data("mtcars")
ui <- shinyUI(fluidRow(
DT::dataTableOutput("myDatatable"),
verbatimTextOutput("selectedCells")
))
df <- cbind(new_name =rownames(mtcars), data.frame(mtcars, row.names= NULL))
server <- shinyServer(function(input, output, session) {
output$myDatatable <- DT::renderDataTable(
df, extensions = 'ColReorder', options = list(colReorder = TRUE),selection = list(mode = "single", target ="cell"),
server = FALSE,
rownames = T
)
output$selectedCells <- renderPrint({
s_val = input$myDatatable_cell_clicked$value
s = input$myDatatable_cells_selected
if (!is.null(s) && ncol(s) != 0) {
df[df$new_name==s_val,]
} else {
NULL
}
})
})
shinyApp(ui, server)
1.In 我的应用程序我只想分别显示 Ex 的每一行的数据如果我单击第一列中的任何值数据应该显示整行 就像我点击 Mazda RX4 它应该显示整行数据
2.with 扩展的帮助 = 'ColReorder' 如果我将第一列拖到其他可点击的位置,我可以将列拖到 table 中
例如,如果我将第 1(new_name) 列移到第 4 列,则可点击功能无法正常工作
任何答案将不胜感激
library(shiny)
library(DT)
data("mtcars")
ui <- shinyUI(fluidRow(
DT::dataTableOutput("myDatatable"),
verbatimTextOutput("selectedCells")
))
df <- cbind(new_name =rownames(mtcars), data.frame(mtcars, row.names= NULL))
server <- shinyServer(function(input, output, session) {
output$myDatatable <- DT::renderDataTable(
df, extensions = 'ColReorder', options = list(colReorder = TRUE),selection = list(mode = "single", target ="cell"),
server = FALSE,
rownames = T
)
output$selectedCells <- renderPrint({
s = input$myDatatable_cells_selected
if (!is.null(s) && ncol(s) != 0) {
mtcars[,1]
} else {
NULL
}
})
})
shinyApp(ui, server)
您可以通过以下方式获取所选单元格的值:
s_val = input$myDatatable_cell_clicked$value
之后,您可以在数据中搜索此值并打印整行:
df[df$new_name==s_val,]
已测试:
library(shiny)
library(DT)
data("mtcars")
ui <- shinyUI(fluidRow(
DT::dataTableOutput("myDatatable"),
verbatimTextOutput("selectedCells")
))
df <- cbind(new_name =rownames(mtcars), data.frame(mtcars, row.names= NULL))
server <- shinyServer(function(input, output, session) {
output$myDatatable <- DT::renderDataTable(
df, extensions = 'ColReorder', options = list(colReorder = TRUE),selection = list(mode = "single", target ="cell"),
server = FALSE,
rownames = T
)
output$selectedCells <- renderPrint({
s_val = input$myDatatable_cell_clicked$value
s = input$myDatatable_cells_selected
if (!is.null(s) && ncol(s) != 0) {
df[df$new_name==s_val,]
} else {
NULL
}
})
})
shinyApp(ui, server)