I'm trying to visualize a valueBox using reactive expression.
The code follows
## server.R ##
server <- function(input, output,session) {
inData <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
if (!is.null(inFile))
return("OK")
})
output$approvalBox <- renderValueBox({
if (is.null(inData())){
valueBox(
"Arggg", "File not yet uploaded", icon = icon("thumbs-down", lib = "glyphicon"),
color = "red"
)
}
else if (inData()=="OK"){
valueBox(
"Great!", paste("You've uploaded the file: ",input$file1$name), icon = icon("thumbs-up", lib = "glyphicon"),
color = "green"
)
}
})
vBoxes <- reactive({
if (inData()=="OK"){
output$dataStats1 <- renderValueBox({
valueBox(
paste0(100, "%"), "Progress", icon = icon("list"),
color = "purple"
)
})
}
})
}
## ui.R ##
library(shinydashboard)
library(shiny)
dashboardPage(
dashboardHeader(title = "Basic Example"),
dashboardSidebar(
sidebarMenu(
menuItem("Data", tabName = "data", icon = icon("th")),
menuItem("Analysis",tabName = "analysis", icon = icon("pagelines"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "data",h3("data"),
fluidRow(
box(
title = "Import",
fileInput('file1', 'Import File',
accept=c('sheetName', 'header'), multiple=FALSE)
),
valueBoxOutput("approvalBox"),
valueBoxOutput("dataStats1")
)
),
tabItem(tabName = "analysis",
h2("Data Analysis")
)
)
)
)
The idea is to display the value boxes only in the occurrence that the file has been imported.
Using the code above the "reactive" value box is not displayed at all.