Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fileInput function not responding in r Shiny

Tags:

r

shiny

I am new to R and R shiny, and have been working on putting together a statistics application that will allow the user to import files, and then run different statistics programs on the data. The fileData function had been working fine for me until recently, and now whenever I attempt to upload a file, nothing opens. I have tried everything I can think of to get it to run, but it appears the file won't attach to the function. Any help will be very much appreciated!

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)
like image 353
emerson Avatar asked Sep 16 '25 09:09

emerson


1 Answers

Tricky because Shiny doesn't give any warning about this :
shiny app will not work if the same "output" is used two times in Ui.R.

Everything looks OK, except the double use of uiOutput("dep1") and 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

You should use an output only once.

like image 198
Waldi Avatar answered Sep 19 '25 03:09

Waldi