0

I refer to codes from shiny widget gallery to create a fileInput widget on my shinydashboard.

ui.R

fluidPage(
    
  # Copy the line below to make a file upload manager
  fileInput("file", label = h3("File input")),
  
  hr(),
  fluidRow(column(4, verbatimTextOutput("value")))
  
)

server.R

function(input, output) {

  # You can access the value of the widget with input$file, e.g.
  output$value <- renderPrint({
    str(input$file)
  })

}

I expect my app to show "file upload progress", "upload complete" status and "summary" of the file just like image below. enter image description here

Below are my codes for shinydashboard: ** for your convenience, refer to "tab Item" = "file".

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(
                          wellPanel(
                            fileInput(inputId = "***csv-upload***", label = "File Upload:",
                                      accept = c("csv", ".csv"))
                          )
                       )
                     )
              )
    )
  )
)


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

shinyApp(ui = ui, server = server)

I click on "Run App", tried to upload csv file but I don't see any progress bar or file upload complete status after I select a file. The widget basically doesn't work at all.

enter image description here

Ong K.S
  • 229
  • 1
  • 4
  • 15
  • 2
    See https://stackoverflow.com/q/62635457/13513328 – Waldi Aug 02 '20 at 06:34
  • Hi @Waldi, thanks for comment. I believe you meant I shouldn't have tabName & inputId sharing same ID "file". I made some changes but it still doesn't work. I edited my question as well to reflect latest and simpler codes. – Ong K.S Aug 02 '20 at 07:29
  • For example you use p1-revenue-book twice in output : this won't work – Waldi Aug 02 '20 at 08:10
  • @Waldi I understand that part. At the moment, I only build an overview on the user interface then will work on the details. Please ignore "future" & "history" tab at the moment. I am working on the first step...file upload. File will be will process and displayed as charts later. Once this part is done, I will move on to "future" & "history". – Ong K.S Aug 02 '20 at 09:38
  • @Waldi I am not sure whether I missed your points. I tidy up all inputId & OutputId, run the app again. It works. Does this mean whenever there is duplicated ID, the app will not work appropriately – Ong K.S Aug 02 '20 at 11:06
  • Exactly ;), this is what the post I linked explains – Waldi Aug 02 '20 at 15:36
  • @Waldi Ok, I get you point now. I always though I can lay down the overview of user interface first. Focus on the InputId/OutputId that I start with, the rest can be dealt with later. Now i know the script will not work if the IDs are not correct, any of them. And the worst part, there is no "alert" from the system after i click "Run App". Thanks. – Ong K.S Aug 03 '20 at 01:56
  • ., happy I could help. don't hesitate to upvote the post I linked : I think it's important to draw attention to this issue which tricked many of us... – Waldi Aug 03 '20 at 14:02

0 Answers0