R Shinydashboard:- fileInput() not functioning

I am trying to incorporate fileInput() for uploading csv file in Shinydashboard.
Below are my codes and the fileInput() is at tabName = "data".

library(shinydashboard)
library(shiny)

define user interface

ui <- dashboardPage(
dashboardHeader(title = "B. Times Square"),
dashboardSidebar(
sidebarMenu(
menuItem(text = "Overview", tabName = "overview", icon = icon("balance-scale-right")),
menuItem(text = "Future", tabName = "future", icon = icon("map-signs")),
menuItem(text = "History", tabName = "history", icon = icon("history")),
menuItem(text = "File Upload", tabName = "data", icon = icon("file-upload"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "overview",
fluidRow(
infoBox(title = "Revenue", 1000, icon = icon("hand-holding-usd")),
infoBox(title = "Transaction", 50, icon = icon("bed")),
infoBox(title = "Occupancy %", 40, icon = icon("percentage"))
)
),
tabItem(tabName = "future",
fluidRow(
box(
title = "Revenue [Book]", width = 4,
plotOutput(outputId = "p1-revenue-book")
),
box(
title = "Revenue [Check-In]", width = 4,
plotOutput(outputId = "p2-revenue-checkin")
),
box(
title = "RevPAR", width = 4,
plotOutput(outputId = "p3-revpar")
)
),
fluidRow(
box(
title = "Revenue [Channel]", width = 4,
plotOutput(outputId = "p4-revenue-channel")
),
box(
title = "Occupancy [unit]", width = 4,
plotOutput(outputId = "p5-occupancy")
),
box(
title = "Book vs Cancel [Unit]", width = 4,
plotOutput(outputId = "p6-book-vs-cancel")
)
)
),
tabItem(tabName = "history",
fluidRow(
box(
title = "Revenue [Check-In]", width = 4,
plotOutput(outputId = "p2-revenue-checkin")
),
box(
title = "Revenue [Book]", width = 4,
plotOutput(outputId = "p1-revenue-book")
),
box(
title = "RevPAR", width = 4,
plotOutput(outputId = "p3-revpar")
)
),
fluidRow(
box(
title = "Revenue [Channel]", width = 4,
plotOutput(outputId = "p4-revenue-channel")
),
box(
title = "Occupancy [unit]", width = 4,
plotOutput(outputId = "p5-occupancy")
),
box(
title = "Book vs Cancel [Unit]", width = 4,
plotOutput(outputId = "p6-book-vs-cancel")
)
)
),
tabItem(tabName = "data",
column(width = 4,
fluidRow(
inputPanel(
fileInput(inputId = "csv-upload", label = "File upload:")
)
)
)
)
)
)
)

define server

server <- function(input, output) {

}

shinyApp(ui = ui, server = server)

I tried to upload same file through a sample in R widget gallery; it works just fine.
Below is the result from widget gallery.

The widget doesn't work on my dashboard. I don't see any file upload progress bar/upload complete bar.

I am not sure where goes wrong. Appreciate your advice.

Hi! Everything is fine in your code, except by the duplicated outputId names in plotOutput() functions for "future" and "history" tabItems. I added "-hist" to "p2-revenue-checkin" etc. and now the fileInput widget is working properly:

# load packages
library(shinydashboard)
library(shiny)

# define user interface
ui <- dashboardPage(
  dashboardHeader(title = "B. Times Square"),
  dashboardSidebar(
    sidebarMenu(
      menuItem(text = "Overview", tabName = "overview", icon = icon("balance-scale-right")),
      menuItem(text = "Future", tabName = "future", icon = icon("map-signs")),
      menuItem(text = "History", tabName = "history", icon = icon("history")),
      menuItem(text = "File Upload", tabName = "data", icon = icon("file-upload"))
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "overview",
              fluidRow(
                infoBox(title = "Revenue", 1000, icon = icon("hand-holding-usd")),
                infoBox(title = "Transaction", 50, icon = icon("bed")),
                infoBox(title = "Occupancy %", 40, icon = icon("percentage"))
              )
      ),
      tabItem(tabName = "future",
              fluidRow(
                box(
                  title = "Revenue [Book]", width = 4,
                  plotOutput(outputId = "p1-revenue-book")
                ),
                box(
                  title = "Revenue [Check-In]", width = 4,
                  plotOutput(outputId = "p2-revenue-checkin")
                ),
                box(
                  title = "RevPAR", width = 4,
                  plotOutput(outputId = "p3-revpar")
                )
              ),
              fluidRow(
                box(
                  title = "Revenue [Channel]", width = 4,
                  plotOutput(outputId = "p4-revenue-channel")
                ),
                box(
                  title = "Occupancy [unit]", width = 4,
                  plotOutput(outputId = "p5-occupancy")
                ),
                box(
                  title = "Book vs Cancel [Unit]", width = 4,
                  plotOutput(outputId = "p6-book-vs-cancel")
                )
              )
      ),
      
      tabItem(tabName = "history",
              fluidRow(
                box(
                  title = "Revenue [Check-In]", width = 4,
                  plotOutput(outputId = "p2-revenue-checkin-hist")
                ),
                box(
                  title = "Revenue [Book]", width = 4,
                  plotOutput(outputId = "p1-revenue-book-hist")
                ),
                box(
                  title = "RevPAR", width = 4,
                  plotOutput(outputId = "p3-revpar-hist")
                )
              ),
              fluidRow(
                box(
                  title = "Revenue [Channel]", width = 4,
                  plotOutput(outputId = "p4-revenue-channel-hist")
                ),
                box(
                  title = "Occupancy [unit]", width = 4,
                  plotOutput(outputId = "p5-occupancy-hist")
                ),
                box(
                  title = "Book vs Cancel [Unit]", width = 4,
                  plotOutput(outputId = "p6-book-vs-cancel-hist")
                )
              )
      ),
      
      tabItem(tabName = "data",
              column(width = 4,
                     fluidRow(
                       inputPanel(
                         fileInput(inputId = "csv-upload", label = "File upload:",
                                   accept = ".csv")
                       )
                     )
              )
      )
    )
  )
)

# define server
server <- function(input, output) {
  
}

# run application
shinyApp(ui = ui, server = server)
1 Like

thanks @gfsarmanho. It works now.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.