我是Shiny的新手,我试图将现有的.R脚本代码转换为Shiny app。
原始代码 - link
示例数据 - link
关键是要有一个文件输入,一个人选择一个pdf文件。比pdf处理。
这是我的代码:
server <- function(input, output) {
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
req(input$file1)
test <- pdf_text(input$file1$datapath)
### Two Sided
test <- gsub("[\r\n]", " ", test)
list <- strsplit(test, " {2,}") #split anywhere where there are 2 or more consecutive spaces - hopefully only between two paragraphs (if not the output wont make much sense)
resi <- lapply(list, function(x) {
unl <- unlist(x)
len <- length(x)
uneven <- seq(from = 1, to = len , by = 2)
even <- seq(from = 2, to = len , by = 2)
uneven <- unl[uneven]
even <- unl[even]
uneven <- paste(uneven, collapse = " ")
even <- paste(even, collapse = " ") #intentionally leave a space between them, one could even use something that is not expected to occur in the document like "frafrafra" and use that in the gsub call later as gsub("(\\d)-frafrafra(\\d)", "\\1\\2", resi)
return(cbind(uneven, even))
}) #separate even from uneven rows
resi <- unlist(resi)
resi <- gsub("(\\d)- (\\d)", "\\1\\2", resi) #clean numbers
resi <- gsub("(\\b)- (\\b)", "\\1\\2", resi) #clean words
resi <- data_frame(line = 1:length(resi), text = resi) #change class/type - vector to dataframe
count <- resi %>%
unnest_tokens(word, text) %>% #split columns into word like elements (tokens)
count(word, sort = TRUE) #count frequency and sort in desc order
count$word <- gsub("[^0-9]", NA, count$word)
count$num_char <- nchar(count$word)
two_cols <- count %>%
filter(!is.na(word)) %>%
filter(n == 1) %>%
filter(num_char == 7 | num_char == 13 | num_char == 15)
if(input$disp == "head") {
return(head(test))
}
else {
return(two_cols)
}
})
}
代码似乎工作到test&lt; - pdf_text(输入$ file ...
但是,我收到了错误消息:错误登录&#39;&#39;参数
任何线索有什么问题?
编辑:
我正在使用原始代码的第二部分进行测试,这似乎是范围规则的一个问题。也就是说,在服务器功能中定义一个功能。