r Shiny 中的 fileInput 函数没有响应

问题描述 投票:0回答:2

我是 R 和 R闪亮的新手,一直致力于构建一个统计应用程序,该应用程序将允许用户导入文件,然后对数据运行不同的统计程序。直到最近,fileData 函数一直对我来说运行良好,现在每当我尝试上传文件时,都不会打开任何内容。我已尝试了所有我能想到的让它运行的方法,但似乎该文件不会附加到该函数。任何帮助将非常感激!

library(shiny)
library(shinyFiles)
library(dplyr)
library(shinythemes)

ui <- fluidPage(theme = shinytheme("cosmo"),
# Application title
titlePanel("Stats"),

# Sidebar
sidebarLayout(
    sidebarPanel(
        tabsetPanel(type = "tab", 
                    tabPanel("SCI",

                        fileInput("file1", "Insert File", multiple = TRUE, accept = c("text/csv", "text/comma-separated-values, text/plain", ".csv")),

                        selectInput("statChoice", "Choose Stats", c("None" = "None", "ANOVA 0 w/in 1 btw" = "A1btw", "ANOVA 0 w/in 2 btw" = "A2btw")),

                            conditionalPanel("statChoice == 'A1btw'",
                                uiOutput("ind1"),
                                uiOutput("dep1")),

                            conditionalPanel("statChoice == 'A2btw'",
                                uiOutput("ind1"),
                                uiOutput("ind2"),
                                uiOutput("dep1")),
            )
        )
    ),

    # Show a plot of the generated distribution
    mainPanel(
       tabsetPanel(type = "tab",
                   tabPanel("Data", 
                            dataTableOutput("fileData")),
                   tabPanel("Summary Statistics"),
                   tabPanel("Graphs"))
    )
    )
)

server <- function(input, output) {
fileData <- eventReactive(input$file1,{
    read.csv(input$file1$dataPath, header = TRUE, sep = ",", dec = ".")
})

output$fileData <- renderDataTable(
    fileData()
)

vars <- reactive({
    names(fileData())
})

output$ind1 <- renderUI({
    selectInput("var1", "Independent 1", choices = vars())
})

output$ind2 <- renderUI({
    selectInput("var2", "Independent 2", choices = vars())
})

output$dep1 <- renderUI({
    selectInput("var3", "Dependent 1", choices = vars())
})
}

shinyApp(ui = ui, server = server)
r shiny
2个回答
4
投票

很棘手,因为 Shiny 没有对此发出任何警告:
如果在 Ui.R 中使用相同的“输出”两次,闪亮的应用程序将无法工作。

一切看起来都不错,除了双重使用

uiOutput("dep1")

uiOutput("ind1")
 :

conditionalPanel("statChoice == 'A1btw'", uiOutput("ind1"), # Used once uiOutput("dep1")), # Used once conditionalPanel("statChoice == 'A2btw'", uiOutput("ind1"), # Used twice uiOutput("ind2"), uiOutput("dep1")), # Used twice
您应该

仅使用一次输出


0
投票
还值得指出的是,如果您的

fileInput

 之前可以工作,但后来在某个时候突然停止工作,那么值得检查它在其他浏览器中的工作方式。例如。在我的应用程序中的 Safari 
fileInput
 中,完全可点击并且对点击做出反应,但在 Chrome 中不再如此(但它以前有效)

© www.soinside.com 2019 - 2024. All rights reserved.