r - 如何在闪亮的应用过滤器/按钮中应用正则表达式?
问题描述
我是 Shiny Apps 和 R 的超级新手。如何添加一个按钮,允许我使用此正则表达式过滤传入的数据集?上传的数据集都将包含相同的列名,我想应用正则表达式的列是“close_notes”。我想首先将此列转换为字符串,将所有内容大写,然后应用 regex。非常感谢您提前提供的帮助!
正则表达式:
"\\bMASTER DATA\\b|\\bSOURCE LIST\\b|\\bVALIDITY DATES\\b|\\bMRP CONTROLLER\\b|\\bPSV\\b|\\bELIGIBILITY\\b|\\bCOST\\b|\\bMARKETING EXCLUSION\\b|\\bEFFECTIVITY\\b|\\bMISSING\\b|\bbBLANK\\b"
下面的代码适用于闪亮的应用程序。请让我知道是否有任何问题或需要修改。谢谢!
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE),
# Button
downloadButton("downloadData", "Download")
),
mainPanel(
dataTableOutput("contents")
)
)
)
server <- function(input, output) {
datasetInput <- reactive({
req(input$file1)
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header = input$header)
})
output$contents <- renderDataTable({
datasetInput()
})
output$downloadData <- downloadHandler(
filename = function() {
paste("myfile",Sys.Date(), ".csv", sep = "")
},
content = function(file) {
write.csv(datasetInput(), file, row.names = FALSE)
}
)
}
shinyApp(ui, server)
解决方案
您应该将单词边界移动到交替的外部,如下所示:
\b(MASTER DATA|SOURCE LIST|VALIDITY DATES|MRP CONTROLLER|PSV|ELIGIBILITY|COST|MARKETING EXCLUSION|EFFECTIVITY|MISSING|BLANK)\b
推荐阅读
- android - BottomNavigationView 设置从某个 url 下载的自定义图标
- jquery - Jquery Datatable 列调整大小无法按预期工作,定义了“columnDefs”列宽
- svg - http 到 https 迁移后解析 SVG 文件的问题
- php - 通过 React 将数据发布到 laravel
- mysql - 从选择查询 MySql 插入记录其他更新
- crystal-reports - 格式化跨越多行的超链接
- python - 如何在 python 字典中保持循环以搜索值?
- javascript - 使用 Moment.js 从日期数组中查找最近的第二天
- asp.net-mvc - 找到多个与 URL 错误 MVC 5 匹配的控制器类型
- c# - 拆分和单元测试 linq-query