1

I am trying to develop an app with a dashboard design to display the summary of the table and display the data frame.

I am quite unsuccessful, in designing it. I have incorporated my own dashboard design for this.

I am missing an element in my server function and not able to see the dataframe of the uplaoded file.

Any lead would be helful.

Below is my code for the UI and Server function

UI

  ui <- dashboardPage(
  dashboardHeader(title = "Model"),
  dashboardSidebar(sidebarMenu(
    id = "tabs",
    menuItem(
      "Data",
      tabName = "data",
      icon = icon("table"),
      startExpanded = TRUE,
      menuSubItem("Load", tabName = "data1")

    ),
    dashboardBody(
      tags$style(
        type = "text/css",
        ".shiny-output-error { visibility: hidden; }",
        ".shiny-output-error:before { visibility: hidden; }"
      ),
      tabItems(tabItem(
        tabName = "data1",
        fluidPage(
          fluidRow(
            fileInput(
              "file",
              "Choose CSV File",
              accept = c("text/csv",
                         "text/comma-seperated-values, text/plain",
                         ".csv")
            ),
            tags$hr(),
            checkboxInput("header", "Header", TRUE),
            radioButtons(
              "sep",
              "Separator",
              choices = c(
                Comma = ",",
                semicolon = ";",
                Tab = "\t"
              ),
              selected = ";"
            )
          ),
          mainPanel(uiOutput("tb"))
        )
      ))
    )
  )

SERVER CODE

server <- shinyServer(function(input,output){
 data <- reactive({
   file1 <- input$file
   if(is.null(file1)){return()}
   read.csv(file = file$datapath, sep=input$sep)
 })
 output$filedf <- renderTable({
   if(is.null(data())){return()}
   input$file
 })
 output$sum <- renderTable({
   if(is.null(data())){return()}
   summary(data())
 })
 output$table <- renderTable({
   if(is.null(data())){return()}
   data()
 })
 output$tb <- renderUI({
   if(is.null(data())){return()}
   tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum"))

 })
  })
2
  • I know, that I making a mistake with Output$tb <- renderUI ; or missing some element in UI.. Could any one help to figure it out. Commented Apr 9, 2018 at 13:06
  • 1
    Just a trival thing here. You do not need to check if(is.null(data())){return()} at every step. As you have checked for null in the reactive function. A simple alternative to that is to use req(input$file), in this way null are taken care. Commented Apr 10, 2018 at 14:38

1 Answer 1

1

turns out there was a small typo in your code. You were referring to input$file and file$datapath, where that should have been input$file1 and file1$datapath. So a working version would be as shown below. Hope this helps!

library(shiny)
library(shinydashboard)

ui<-dashboardPage(
  dashboardHeader(title = "Model"),
  dashboardSidebar(
    sidebarMenu(id="tabs",
                menuItem("Data", tabName = "data", icon = icon("table"),startExpanded = TRUE,
                         menuSubItem("Load", tabName = "data1")

                ),
                menuItem("Visualisation",icon=icon("bar-chart-o"), tabName = "vis"),
                menuItem("Result", icon=icon("cog"), tabName = "result")
    )
  ),
  dashboardBody(
    tags$style(type="text/css",
               ".shiny-output-error { visibility: hidden; }",
               ".shiny-output-error:before { visibility: hidden; }"
    ),
    tabItems(
      tabItem(tabName = "data1",
              fluidPage(
                fluidRow(
                  fileInput("file1","Choose CSV File",
                            accept = c("text/csv",
                                       "text/comma-seperated-values, text/plain",
                                       ".csv")
                  ),
                  tags$hr(),
                  checkboxInput("header", "Header", TRUE),
                  radioButtons("sep","Separator",
                               choices=c(Comma=",",
                                         semicolon=";",
                                         Tab="\t"),
                               selected = ";")
                ),
                mainPanel(
                  uiOutput("tb")
                )
              )
      )
    )
  )
) 


server <- shinyServer(function(input,output){
  data <- reactive({
    file1 <- input$file1
    if(is.null(file1)){return()}
    read.csv(file = file1$datapath, sep=input$sep)
  })
  output$filedf <- renderTable({
    if(is.null(data())){return()}
    input$file1
  })
  output$sum <- renderTable({
    if(is.null(data())){return()}
    summary(data())
  })
  output$table <- renderTable({
    if(is.null(data())){return()}
    data()
  })
  output$tb <- renderUI({
    if(is.null(data())){return()}
    tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))

  })
})



shinyApp(ui,server)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.