r - 通过闪亮应用程序中的列名组合子集数据框
问题描述
我有下面的数据框:
DF2 = data.frame(agency_postcode = factor(rep(c(12345,45678,24124,32525,32325),2)),
car_group=factor(rep(c("Microcar","City car","Supermini","Compact","SUV"),2)),
transmission=factor(rep(c("automatic","manual"),5)))
我有一个闪亮的,用户从中选择一个或多个列名。What I want to achieve is after selecting a column name to have return all the values of the dataframe equal to the first row of this column.The same logic should be applied when more than one columns selected.So for example if I select all three列然后必须返回数据框的第一行而不是无。
#ui.r
library(shiny)
library(DT)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("sel","Filter by:",
choices = colnames(DF2),
multiple=T,selected = "agency_postcode")
),
mainPanel(
DT::dataTableOutput("D")
)
)
)
#server.r
#server.r
library(shiny)
library(DT)
server <- function(input, output) {
output$D<-renderDataTable({
DE<-DF2[ which(DF2[,input$sel] %in% DF2[1, input$sel]), ]
datatable(DE)
})
}
解决方案
推荐阅读
- c# - 计算异步按钮被按下的次数(或者是否正在进行某些操作)
- c# - 从 Native C++ 使用通用 Windows C# 类库
- android - Android 外设需要配对
- c++ - 编译器报告“已删除”运算符 = ,但它在那里
- ios - 检查 URL 是否与 UIWebView 的请求或 WKWebView 的 navigationAction.request 相等
- javascript - Angular - 错误类型错误:_co.timeIn 不是函数
- angular - Angular 6 'ng build --prod' 不会缩小/丑化 index.html
- google-apps-script - 从 Android 访问 Google Apps 脚本编辑器
- excel - Tableau 日期和时间
- c# - 如何检查 datagridview 是否已排序?