【问题标题】:fileInput function not responding in r Shinyr Shiny中的fileInput函数没有响应
【发布时间】:2021-05-19 12:25:08
【问题描述】:

我是 R 和 R shiny 的新手,并且一直致力于组合一个统计应用程序,该应用程序将允许用户导入文件,然后对数据运行不同的统计程序。直到最近,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


    【解决方案1】:

    很棘手,因为 Shiny 没有对此发出任何警告:
    shiny app will not work if the same "output" is used two times in 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
    

    您应该只使用一次输出

    猜你喜欢
    • 2020-08-15
    • 2018-06-04
    • 2018-06-20
    • 1970-01-01
    • 2020-10-19
    • 2019-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多