I have little problem. I have build package called d3K that can be used across different dashboard. One of function is as follows:
conditionalRenderValueBox <- function(value, title, red_limit, yellow_limit){
renderValueBox( valueBox(value, title,
color = if(class(value)=="character" | is.na(value)){
"blue"
}else if(value>red_limit ){
"red"
}else if(value>yellow_limit){
"yellow"
}else{
"green"
}
))
}
Now I am trying to pass value parameter in function, where parameter is reactive value.
server.R
library(lubridate)
# library(googleVis)
# library(readr)
library(shinyjs)
library(ggplot2)
library(plotly)
library(d3K)
library(dplyr)
server <- function(input, output, session) {
v1 = reactive({
input$v1
})
f <- reactive({
if(is.na(v1())){
"WAI"
}else{
runif(1, 1, 10)
}
})
output$t <- conditionalRenderValueBox(f(), "Possible Value", 15, 10)
}
ui.R
library(shinydashboard)
library(shiny)
library(shinyjs)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "DashBoard")
,skin = 'yellow'
,dashboardSidebar(
tags$head(
tags$style(HTML("
.sidebar { height: 90vh; overflow-y: auto; }
" )
)
),
sidebarMenu(
menuItem("R", tabName = "R", icon = icon("cog"))
, selectInput("v1", label = h3("Select box"),
choices = list( 1, 11, 15),
selected = 1),
)
)
,dashboardBody(
tabItems(
tabItem(
tabName = "R"
, br()
, fluidRow(
valueBoxOutput("t")
)
)
)
)
)
I am not able to see value box in shiny dashboard.
However, if use following code in plase of output$t in server , it works
output$t <- renderValueBox( valueBox(f(), "title",
color = if(class(f())=="character" | is.na(f())){
"blue"
}else if(f()>red_limit ){
"red"
}else if(f()>yellow_limit){
"yellow"
}else{
"green"
}
))
Then I am able to see result as expected