【问题标题】:How to use local .txt files in a Shiny App如何在 Shiny App 中使用本地 .txt 文件
【发布时间】:2018-01-20 14:07:13
【问题描述】:

大家好,这是我的第一个问题,所以我希望格式正确。

我正在寻找创建一个 R 闪亮应用程序,它调用用户设置的参数内的所有 .txt 文件,合并这些 .txt 文件,并生成一个词云。

位于https://lukaszsowinski.shinyapps.io/WC-app/ 的应用程序一旦打开就会崩溃,尽管它可以在我的本地计算机上运行。我几乎可以肯定这与我在 wd()、数据文件和 .txt 文件中的写入方式有关,因为它们在我最终发布之前给我带来了问题。这是我遇到的错误

2017-08-12T01:17:22.742107+00:00 shinyapps[204302]:loadWorkbook(文件)中的错误: 2017-08-12T01:17:22.742109+00:00 shinyapps[204302]:找不到 /home/shiny/WC-app/WordMappingInfo.xlsx

这是我不确定我的错误在哪里的代码片段。

library(rsconnect)
rsconnect::deployApp('C:/Users/Lukasz Sowinski/Desktop/WC-app')

server <- function(input, output, server) 
{

textframe <- read.xlsx("C:/Users/Lukasz Sowinski/Desktop/WC-app/WordMappingInfo.xlsx", 1)

schooldata <- list (
    "Num" = textframe$Num[!is.na(textframe$Num)],
    "SchoolName" = C(textframe$SchoolName),
    "Path" = c(
        "C:/Users/Lukasz Sowinski/Desktop/WC-app/texts/Queens College.txt",
        "C:/Users/Lukasz Sowinski/Desktop/WC-app/texts/Lehman College.txt",
        "C:/Users/Lukasz Sowinski/Desktop/WC-app/texts/Denison University.txt", 
        "C:/Users/Lukasz Sowinski/Desktop/WC-app/texts/St Johns University.txt",
        "C:/Users/Lukasz Sowinski/Desktop/WC-app/texts/Rutgers University.txt"
    ),
    "Students" = textframe$Students[!is.na(textframe$Students)],
    "Tuition" = textframe$Tuition[!is.na(textframe$Tuition)],
    "Program" = textframe$Program[!is.na(textframe$Program)]
)

这是我根据用户输入根据需要调用数据的部分代码。

if (schooldata$Program[i] == input$selection)
                {

                    if (temptext == 0)
                    {
                        temptext <- schooldata$Path[i]
                        temptext.1 <- readLines(temptext)
                        mastertext.1 = temptext.1
                    }

                    temptext <- schooldata$Path[i]
                    temptext.1 <- readLines(temptext)
                    mastertext.1 <- rbind(mastertext.1, temptext.1)

                }

我也尝试过使用路径 “./WC-app/WordMappingInfo.xlsx” “~/WC-app/WordMappingInfo.xlsx” 我在类似的问题中发现了这一点,但都不起作用。

任何帮助将不胜感激。谢谢

【问题讨论】:

  • 您将代码指向本地计算机上的一个文件,shinyapps.io 无权访问该文件。使情况复杂化的是,在shinyapps.io 上,您不知道文件夹在哪里。你可以试试“~/texts/Queens College.txt”
  • 试试 "./texts/Queens College.txt" 另外我会去掉名字中的所有空格,因为 linux 不喜欢它们。

标签: r file shiny shinyapps


【解决方案1】:

您是否尝试过使用 shinyFiles CRAN 包扩展?

在 ui.R 文件中

shinyUI(bootstrapPage(
    shinyFilesButton('files', label='File select', title='Please select a file', multiple=FALSE)
))

在 server.R 文件中

shinyServer(function(input, output) {
    shinyFileChoose(input, 'files', root=c(root='.'), filetypes=c('', 'txt'))
})

【讨论】:

    猜你喜欢
    • 2017-12-27
    • 1970-01-01
    • 2017-05-04
    • 2017-01-26
    • 1970-01-01
    • 2012-10-22
    • 2014-11-07
    • 2018-01-20
    • 1970-01-01
    相关资源
    最近更新 更多