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"))
})
})
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 usereq(input$file), in this way null are taken care.