R dashboard plot issues - r

For simplicity, assume the BTC, ETH, XRP data is an arbitrary list of numbers ie: 4000, 5000, 500 etc. The data from the web and my excel files is not implemented this version and I have added fake data for anyone to recreate my problem with the Plots. My problem is that everything works and the dashboard comes up, but the plots will not appear. It has something to do with my server function, and I know It needs to be reactive in some form. I have not found a solution that fixes my problem. let me know if I can help in any way or answer any questions. Thanks! (I also know not all library functions are being used at this moment)
Additionally, if anyone knows how to implement the selected dates as the used input for the plots that would be awesome as well! Right now I am using a slider input for simplicity. I will also change the plot to a line graph. For now, if someone could help me with the reactivity that would be great!
`
library(shiny)
library(shinydashboard)
library(ggplot2)
library(gdata)
library(rvest)
# setwd("C:/Users/Zach/Documents/app.R/fuckk you")
# url <- "https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20180811"
# BTCALL <- url %>%
# html() %>%
# html_nodes(xpath='//*[#id="historical-data"]/div/div[2]/table') %>%
# html_table()
# BTCALL <- BTCALL[[1]]
#
# url <- "https://coinmarketcap.com/currencies/ethereum/historical-data/?start=20130428&end=20180811"
# ETHALL <- url %>%
# html() %>%
# html_nodes(xpath='//*[#id="historical-data"]/div/div[2]/table') %>%
# html_table()
# ETHALL <- ETHALL[[1]]
#
# url <- "https://coinmarketcap.com/currencies/ripple/historical-data/?start=20130428&end=20180811"
# XRPALL <- url %>%
# html() %>%
# html_nodes(xpath='//*[#id="historical-data"]/div/div[2]/table') %>%
# html_table()
# XRPALL <- XRPALL[[1]]
# df <- read.xls("Rdata.xlsx",
# sheet = 1,
# perl="c:/Perl64/bin/perl")
#
# BTC <- df[,2]
# ETH <- df[,3]
# XRP <- df[,4]
# DataDate <- df[,1]
Date <- Sys.Date()
class(as.Date(Date))
Start <- Date
End <- Date+8
BTC = c(5000,6000,7000,8000,9000,10000,11000,12000)
ETH = c(300,400,500,600,700,800,900,1000,1100,1200)
XRP = c(.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.2,1.3,1.4)
ui <- fluidPage(
dashboardPage( skin = "black",
dashboardHeader(title = tags$a(tags$img(src="Apollo.png", height ='58', width ='220'),
'Apollo Projections'),
dropdownMenu(type = "message",
messageItem(from = "btc Updates", message = "BTC ETF to be launched soon", time = "12:00")
),
dropdownMenu(type = "notifications",
notificationItem(
text = "2 new tabs added!",
icon = icon("dashboard"),
status = "success"
)
),
dropdownMenu(type = "tasks",
taskItem(
value = 62,
color = "red",
text = "Read BTC manuel"
),
taskItem(
value = 22,
color = "aqua",
text = "Read ETH manuel"
))
),
dashboardSidebar(
sidebarMenu(
menuItem("BTC", tabName = "BTC",icon = icon("bitcoin")),
menuSubItem("Volume", tabName = "BTCV"),
menuSubItem("MarketCap", tabName = "BTCM"),
menuItem("ETH", tabName = "Eth"),
menuItem("XRP", tabName = "Xrp", badgeLabel = "New", badgeColor = "aqua")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "BTC",
fluidRow(
infoBox("Current BTC Price Change",paste("%",round(BTC/BTC,digits = 4)), icon = icon("bitcoin")),
infoBox("Tomorrow BTC Price Change",paste("%",round(BTC[2]/BTC,digits = 4)), icon = icon("warning"), color = "blue"),
infoBox("Weekly BTC Price Change",paste("%",round(BTC[7]/BTC,digits = 4)), icon = icon("bar-chart-o"), color = "red")
),
fluidRow(
valueBox(paste("$",round(BTC,digits = 2)), "BTC Price Today", icon = icon("hourglass-3")),
valueBox(paste("$",round(BTC[2],digits = 2)), "BTC Price Tomorrow", icon = icon("diamond"), color = "blue"),
valueBox(paste("$",round(BTC[7],digits = 2)), "BTC Price in 1 Week", icon = icon("globe"),color ="red")
),
fluidRow(
box(title = "BTC Projections", status = "primary", solidHeader = T, plotOutput("Bhisto", height = "500px")),
box (title = "Controls for BTC", status = "primary", solidHeader = T,
sliderInput("NUM","Days for BTC",1,100,50),
dateInput("BTCdate1", "Starting Date", value = Date), dateInput("BTCdate2", "Ending Date", value = Date+6)),
##function for Chart
Final <- difftime(End ,Start , units = c("days")),
textOutput(Final)
)),
tabItem(tabName = "BTCV",
h1("BTC Volume Projections")
),
tabItem(tabName = "BTCM",
h1("BTC MarketCap Projections")
),
tabItem(tabName = "Eth",
fluidRow(
infoBox("Current ETH Price Change",paste("%",round(ETH/ETH,digits = 4)), icon = icon("bitcoin")),
infoBox("Tomorrow ETH Price Change",paste("%",round(ETH[2]/ETH,digits = 4)), icon = icon("warning"), color = "blue"),
infoBox("Weekly ETH Price Change",paste("%",round(ETH[7]/ETH,digits = 4)), icon = icon("bar-chart-o"), color = "red")
),
fluidRow(
valueBox(paste("$",round(ETH,digits = 2)), "ETH Price Today", icon = icon("hourglass-3")),
valueBox(paste("$",round(ETH[2],digits = 2)), "ETH Price Tomorrow", icon = icon("diamond"), color = "blue"),
valueBox(paste("$",round(ETH[7],digits = 2)), "ETH Price in 1 Week", icon = icon("globe"),color ="red")
),
fluidRow(
box(title = "ETH Projections", status = "primary", solidHeader = T, plotOutput("Ehisto", height = "500px")),
box (title = "Controls for ETH", status = "primary", solidHeader = T,
sliderInput("NUM2","Days for ETH",1,100,50),
dateInput("ETHdate1", "Starting Date", value = Date), dateInput("ETHdate2", "Ending Date", value = Date+6)),
##function for Chart
Final <- difftime(End ,Start , units = c("days")),
textOutput(Final)
)),
tabItem(tabName = "Xrp",
fluidRow(
infoBox("Current XRP Price Change",paste("%",round(XRP/XRP,digits = 4)), icon = icon("bitcoin")),
infoBox("Tomorrow XRP Price Change",paste("%",round(XRP[2]/XRP,digits = 4)), icon = icon("warning"), color = "blue"),
infoBox("Weekly XRP Price Change",paste("%",round(XRP[7]/XRP,digits = 4)), icon = icon("bar-chart-o"), color = "red")
),
fluidRow(
valueBox(paste("$",round(XRP,digits = 2)), "XRP Price Today", icon = icon("hourglass-3")),
valueBox(paste("$",round(XRP[2],digits = 2)), "XRP Price Tomorrow", icon = icon("diamond"), color = "blue"),
valueBox(paste("$",round(XRP[7],digits = 2)), "XRP Price in 1 Week", icon = icon("globe"),color ="red")
),
fluidRow(
box(title = "XRP Projections", status = "primary", solidHeader = T, plotOutput("Xhisto", height = "500px")),
box (title = "Controls for XRP", status = "primary", solidHeader = T,
sliderInput("NUM3","Days for XRP",1,100,50),
dateInput("XRPdate1", "Starting Date", value = Date), dateInput("XRPdate2", "Ending Date", value = Date+6)),
##function for Chart
Final <- difftime(End ,Start , units = c("days")),
textOutput(Final)
))
)
)
)
)
server = function(input, output){
output$Bhisto <- renderPlot({
plot(BTC,breaks = input$NUM)
})
output$Ehisto <- renderPlot({
plot(ETH,breaks = input$NUM2)
})
output$Xhisto <- renderPlot({
plot(XRP,breaks = input$NUM3)
})
}
shinyApp(ui = ui, server = server)
`

The problem was the elements not enclosed in the box(). namely Function for Chart in all three tabItems.
I have commented out the two lines in each tabItem
# Final <- difftime(End ,Start , units = c("days")),
# textOutput(Final)
I am not sure what you are trying to do with the above two lines. Here are a few pointers:
If you are looking to use an input value in ui, you can use input.inputId (in the server you will use input$inputId)
Use box() around this textOutput()
Move fixed calculations (like Final) out of ui.
Also, check the warning messages you are getting in the console when you run the app.
Here is the working code:
library(shiny)
library(shinydashboard)
library(ggplot2)
library(gdata)
library(rvest)
# setwd("C:/Users/Zach/Documents/app.R/fuckk you")
# url <- "https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20180811"
# BTCALL <- url %>%
# html() %>%
# html_nodes(xpath='//*[#id="historical-data"]/div/div[2]/table') %>%
# html_table()
# BTCALL <- BTCALL[[1]]
#
# url <- "https://coinmarketcap.com/currencies/ethereum/historical-data/?start=20130428&end=20180811"
# ETHALL <- url %>%
# html() %>%
# html_nodes(xpath='//*[#id="historical-data"]/div/div[2]/table') %>%
# html_table()
# ETHALL <- ETHALL[[1]]
#
# url <- "https://coinmarketcap.com/currencies/ripple/historical-data/?start=20130428&end=20180811"
# XRPALL <- url %>%
# html() %>%
# html_nodes(xpath='//*[#id="historical-data"]/div/div[2]/table') %>%
# html_table()
# XRPALL <- XRPALL[[1]]
# df <- read.xls("Rdata.xlsx",
# sheet = 1,
# perl="c:/Perl64/bin/perl")
#
# BTC <- df[,2]
# ETH <- df[,3]
# XRP <- df[,4]
# DataDate <- df[,1]
Date <- Sys.Date()
class(as.Date(Date))
Start <- Date
End <- Date+8
BTC = c(5000,6000,7000,8000,9000,10000,11000,12000)
ETH = c(300,400,500,600,700,800,900,1000,1100,1200)
XRP = c(.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.2,1.3,1.4)
ui <- fluidPage(
dashboardPage( skin = "black",
dashboardHeader(title = tags$a(tags$img(src="Apollo.png", height ='58', width ='220'),
'Apollo Projections'),
dropdownMenu(type = "message",
messageItem(from = "btc Updates", message = "BTC ETF to be launched soon", time = "12:00")
),
dropdownMenu(type = "notifications",
notificationItem(
text = "2 new tabs added!",
icon = icon("dashboard"),
status = "success"
)
),
dropdownMenu(type = "tasks",
taskItem(
value = 62,
color = "red",
text = "Read BTC manuel"
),
taskItem(
value = 22,
color = "aqua",
text = "Read ETH manuel"
))
),
dashboardSidebar(
sidebarMenu(
menuItem("BTC", tabName = "BTC",icon = icon("bitcoin")),
menuSubItem("Volume", tabName = "BTCV"),
menuSubItem("MarketCap", tabName = "BTCM"),
menuItem("ETH", tabName = "Eth"),
menuItem("XRP", tabName = "Xrp", badgeLabel = "New", badgeColor = "aqua")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "BTC",
fluidRow(
infoBox("Current BTC Price Change",paste("%",round(BTC/BTC,digits = 4)), icon = icon("bitcoin")),
infoBox("Tomorrow BTC Price Change",paste("%",round(BTC[2]/BTC,digits = 4)), icon = icon("warning"), color = "blue"),
infoBox("Weekly BTC Price Change",paste("%",round(BTC[7]/BTC,digits = 4)), icon = icon("bar-chart-o"), color = "red")
),
fluidRow(
valueBox(paste("$",round(BTC,digits = 2)), "BTC Price Today", icon = icon("hourglass-3")),
valueBox(paste("$",round(BTC[2],digits = 2)), "BTC Price Tomorrow", icon = icon("diamond"), color = "blue"),
valueBox(paste("$",round(BTC[7],digits = 2)), "BTC Price in 1 Week", icon = icon("globe"),color ="red")
),
fluidRow(
box(title = "BTC Projections", status = "primary", solidHeader = T, plotOutput("Bhisto")),
box (title = "Controls for BTC", status = "primary", solidHeader = T,
sliderInput("NUM","Days for BTC",1,100,50),
dateInput("BTCdate1", "Starting Date", value = Date), dateInput("BTCdate2", "Ending Date", value = Date+6))
##function for Chart
# Final <- difftime(End ,Start , units = c("days")),
# textOutput(Final)
)),
tabItem(tabName = "BTCV",
h1("BTC Volume Projections")
),
tabItem(tabName = "BTCM",
h1("BTC MarketCap Projections")
),
tabItem(tabName = "Eth",
fluidRow(
infoBox("Current ETH Price Change",paste("%",round(ETH/ETH,digits = 4)), icon = icon("bitcoin")),
infoBox("Tomorrow ETH Price Change",paste("%",round(ETH[2]/ETH,digits = 4)), icon = icon("warning"), color = "blue"),
infoBox("Weekly ETH Price Change",paste("%",round(ETH[7]/ETH,digits = 4)), icon = icon("bar-chart-o"), color = "red")
),
fluidRow(
valueBox(paste("$",round(ETH,digits = 2)), "ETH Price Today", icon = icon("hourglass-3")),
valueBox(paste("$",round(ETH[2],digits = 2)), "ETH Price Tomorrow", icon = icon("diamond"), color = "blue"),
valueBox(paste("$",round(ETH[7],digits = 2)), "ETH Price in 1 Week", icon = icon("globe"),color ="red")
),
fluidRow(
box(title = "ETH Projections", status = "primary", solidHeader = T, plotOutput("Ehisto", height = "500px")),
box (title = "Controls for ETH", status = "primary", solidHeader = T,
sliderInput("NUM2","Days for ETH",1,100,50),
dateInput("ETHdate1", "Starting Date", value = Date), dateInput("ETHdate2", "Ending Date", value = Date+6))
##function for Chart
# Final <- difftime(End ,Start , units = c("days")),
# textOutput(Final)
)),
tabItem(tabName = "Xrp",
fluidRow(
infoBox("Current XRP Price Change",paste("%",round(XRP/XRP,digits = 4)), icon = icon("bitcoin")),
infoBox("Tomorrow XRP Price Change",paste("%",round(XRP[2]/XRP,digits = 4)), icon = icon("warning"), color = "blue"),
infoBox("Weekly XRP Price Change",paste("%",round(XRP[7]/XRP,digits = 4)), icon = icon("bar-chart-o"), color = "red")
),
fluidRow(
valueBox(paste("$",round(XRP,digits = 2)), "XRP Price Today", icon = icon("hourglass-3")),
valueBox(paste("$",round(XRP[2],digits = 2)), "XRP Price Tomorrow", icon = icon("diamond"), color = "blue"),
valueBox(paste("$",round(XRP[7],digits = 2)), "XRP Price in 1 Week", icon = icon("globe"),color ="red")
),
fluidRow(
box(title = "XRP Projections", status = "primary", solidHeader = T, plotOutput("Xhisto", height = "500px")),
box (title = "Controls for XRP", status = "primary", solidHeader = T,
sliderInput("NUM3","Days for XRP",1,100,50),
dateInput("XRPdate1", "Starting Date", value = Date), dateInput("XRPdate2", "Ending Date", value = Date+6))
##function for Chart
# Final <- difftime(End ,Start , units = c("days")),
# textOutput(Final)
))
)
)
)
)
server = function(input, output){
output$Bhisto <- renderPlot({
plot(BTC)
})
output$Ehisto <- renderPlot({
plot(ETH,breaks = input$NUM2)
})
output$Xhisto <- renderPlot({
plot(XRP,breaks = input$NUM3)
})
}
shinyApp(ui, server)

Related

R shiny tabbox plot overlapping

I have an shiny dashboard that contains multiple tabpanels, boxes that has datatable and plots.
With in the first panel tab, I have a datatable followed by two plot objects. I have put the plots into separate collapsible boxes. The issue I have is the plot is overlapping. I tried adjusting the heights to the box/tab box but I still get the overlapping plot.
I am looking at the 'Drug' tabpanel and the two plot objects are: plotlyOutput("drug_cleveland_plot") and plotOutput("drug_forest_plot").
I set the height of the box : height = 3000
Height of the plot that is overlapping: height = 1000
UI:
tabItem(
tabName = "comorbidities",
box(title = p("Medical History",
div(class = "qv_buttons",
actionButton("run_med_history", "Generate Report", icon = icon("refresh")),
shinyWidgets::radioGroupButtons("med_history_pop", label = NULL,
choices = list(#"Previously & Newly Diagnosed",
"Previously Diagnosed",
"Newly Diagnosed"),
selected = "Previously Diagnosed")
)
),
status = "success",
solidHeader = TRUE,
width = 12,
box(
width = 12 ,
height = 3000,
br(),
tabBox(
id = "med_history_tab",
tabPanel(
"Drug",
pickerInput(
inputId = "drug_class_selection",
label = "Drug Class:",
choices = c('ATC 1st', 'ATC 2nd', 'ATC 3rd', 'ATC 4th', 'ATC 5th', 'Ingredient'),
width = '50%'
),
DT::dataTableOutput("truven_med_history_drug_table", width = "850px"),
box(title = "Expected vs Observed Proportion Cleveland Plot",
collapsible = TRUE,collapsed = TRUE, plotlyOutput("drug_cleveland_plot"),width = "100%"),
box(title = "Expected vs Observed Proportion Odds Ratio",
collapsible = TRUE,collapsed = TRUE, plotOutput("drug_forest_plot"),width = "100%")),
tabPanel(
"Condition",
pickerInput(
inputId = "condition_hrc_selection",
label = "Condition Level:",
choices = c(0,1),
choicesOpt = list(subtext = c(" : Acual"," : 1 Level Higher")),
width = '50%'
),
#verbatimTextOutput('sel.cond'),
DT::dataTableOutput("truven_med_history_condition_table"),
actionButton('resetSelection', label = "Click to reset row selection"),
plotlyOutput('cond_cleveland_plot')
),
tabPanel(
"Procedure",
pickerInput(
inputId = "procedure_hrc_selection",
label = "Procedure Level:",
choices = c(0,1),
choicesOpt = list(subtext = c(" : Acual"," : 1 Level Higher")),
width = '50%'
),
#verbatimTextOutput('sel.proc'),
DT::dataTableOutput("truven_med_history_procedure_table")
),
tabPanel(
"Charlson Cormobidity",
DT::dataTableOutput("truven_med_history_cci_table"),
plotlyOutput("truv_cci_bar_plotly"),
br(),
plotlyOutput("cci_bar_plotly")
),
#plotOutput("truven_atc1_plot"),
#plotOutput("truven_icd3_plot")#,
#DT::dataTableOutput("truven_med_history_drug_table")
width = 12,
height = 3000
)
)
Code to create the plot
Server:
# drug cleaveland plot
output$drug_cleveland_plot = renderPlotly({
df <- df_drug_plot()
df <- sqldf("select distinct concept_name,w_cond_rate as rate,'Diagnosed' as grp from df
union
select distinct concept_name,w_exp_rate as rate,'Expected' as grp from df
")
df <- df %>%
arrange(rate) %>% mutate(grp = factor(grp)) %>%
mutate(concept_name=factor(concept_name))
p <- df %>%
arrange(grp, rate, desc(concept_name)) %>%
ggplot(aes(rate, fct_inorder(concept_name))) +
geom_line(aes(group = concept_name)) +
geom_point(aes(color = grp)) +
scale_x_continuous(breaks = seq(0, 1.1, by = 0.1)) +
theme_bw() +
theme(panel.grid.major.x = element_line( linetype = "dotted", size = 0.2, color = 'grey' )) +
scale_colour_manual(values=c("#d91e4a", "#939597")) +
theme (legend.title=element_blank())
m <- list(
l = 200,
r = 100,
b = 100,
t = 100,
pad = 5
)
fig <- ggplotly(p,width = 1500, height = 1000) %>% layout(title = "Drugs: Observed vs Expected Proportion",
autosize = F,
margin = m,
yaxis = list(title = "",
automargin = TRUE),
legend = list(title=list(text='<b> Group </b>')))
fig
})

render the clicked tab R dashboard

I am working on shinydashboard app with multiple tabs & I would like to render the tab content only when it is clicked on. I'm using shinydashboard library to create my dashboard, the application takes around 30 sec to work and I would like to optimize it so it will render the selected tab only.
UI code sample
dashboardPage(
dashboardHeader(title = "Enrollment Dashboard",titleWidth = 300),
sidebar <- dashboardSidebar(width = 300,
sidebarMenu(
menuItem("Descriptive Analysis", icon = icon("right",lib='glyphicon'), tabName = "desc",
menuSubItem("Statistics",icon = icon("right",lib='glyphicon'),tabName = "kpi" ),
menuSubItem("Marketing" ,icon = icon("right",lib='glyphicon'), tabName = "markd")),
menuItem("Predictive Analysis", icon = icon("right",lib='glyphicon'), tabName = "predictive",
menuItem("Enrollment Number", icon = icon("right",lib='glyphicon'), tabName = "predictive",
menuSubItem("Enrollment prediction - overall" ,icon = icon("right",lib='glyphicon'), tabName = "predictivesummary"),
menuItem("Enrollment prediction per program" , icon = icon("right",lib='glyphicon'),tabName = "predictiveprograms"))
dashboardBody(
tags$head(tags$link(rel = "stylesheet" , type = "text/css" , href = "reload.CSS")),
renderText("test"),
tabItems(tabItem(tabName = "kpi",
frow1<-fluidRow(
infoBoxOutput("value1",width = 3),tags$style("#value1 { padding-top:0px; padding-bottom:0px;color: blue; font-size: 13px;background:#F4F4F4;}"),
infoBoxOutput("value2",width = 3),tags$style("#value2 { padding-top:0px; padding-bottom:0px;color: blue; font-size: 13px;background:#F4F4F4;}"),
box
(uiOutput("value3"),
width = 1,
height = 130
),
box
(uiOutput("value5"),
width = 1,
height = 130
),
box
(uiOutput("value6"),
width = 1,
height = 130
),
infoBoxOutput("value4",width = 3),tags$style("#value4 {padding-top:0px; padding-bottom:0px;color: blue; font-size: 13px;background:#F4F4F4;}")
),
frow2<-fluidRow(
box(
title = "Inquiry (Actuals- Green/Target- Light Grey)"
,width = 3
,height = 330
,status = "warning"
,solidHeader = FALSE
,collapsible = TRUE
,dataTableOutput("plot")
),
box(
title = "Applied (Actuals- Green/Target- Light Grey)"
,width = 3
,status = "warning"
,solidHeader = FALSE
,collapsible = TRUE
,plotlyOutput("applyplot", height = 270)
),
box(
title = "Processed (Actuals- Green/Target- Light Grey)"
,width = 3
,status = "warning"
,solidHeader = FALSE
,collapsible = TRUE
,plotlyOutput("processedplot", height = 270)
),
box(
title = "Enrolled (Actuals- Green/Target- Light Grey)"
,width = 3
,status = "warning"
,solidHeader = FALSE
,collapsible = TRUE
,plotlyOutput("enrolledplot", height = 270)
)),
frow3<-fluidRow(
box(
title = "Enrollment Yearly Progress Growth / Programs "
,width = 12
,solidHeader = FALSE
,collapsible = TRUE
,status = "warning",
tabsetPanel( type = 'pills',
tabPanel('Admissions',
plotlyOutput("threerow", height = 350)
),
tabPanel('Financial',plotlyOutput("frow", height = 350)),
tabPanel('Enrollment',plotlyOutput("erow", height = 350))
)
))
),
tabItem(tabName = "predictivesummary" ,
frow5<- fluidRow(
box("Yearly Predictive Analysis"
,width = 12
,solidHeader = FALSE
,collapsible = TRUE
,status = "warning"
,plotlyOutput("plot_forecast" , height = 350) )),
frow501<- fluidRow(
box("Overall Prediction Yearly - Tabular"
,width = 12
,solidHeader = FALSE
,collapsible = TRUE
,status = "warning"
,dataTableOutput("year_table" , height = 350) ))
)
Server
shinyServer(function(input, output ,session ) {
output$value1 <- renderInfoBox({
infoBox(
h2(total.TotalInquiry()),
h4(percentage.TotalInquiry())
,tags$h5('Inquries - Target : ' , total.TargetInquiry())
,
icon = icon("question-sign",lib='glyphicon')
)})
output$value2 <- renderInfoBox({
infoBox(
h2(total.Applied()),
h4(percentage.Applied())
,h5('Applied-Target:',target.Applied())
,
icon = icon("thumbs-up",lib='glyphicon'))
})
output$value3 <- renderText({
paste0(h3(ProcessedA.Accepted()) ,
paste0(percentagepA.Accepted(),'%'),
paste0(),
h5('Processed:' , ProcessedT.Accepted()))
})
output$value5 <- renderText({enter code here
paste0(h3(Processed.Rejected()),h6('Rejected:' ))
})
output$value6 <- renderText({
paste0(h3(Processed.Dropped()),h6('Withdrawan:' ))
})
output$value4 <- renderInfoBox({
infoBox(
#tags$h2(total.enrolled() ,'~' , percentage.enrolled())
tags$h2(total.enrolled()),
h4(percentage.enrolled())
,tags$h5('Enrolled-Target:',target.enrolled())
,
#color = "olive" , fill = TRUE
icon = icon("check",lib='glyphicon') )
})
output$plot <- DT::renderDataTable(expr ={
g <- IA.Applied()
} , options = list(dom = 't',scrollX = TRUE,autowidth = TRUE,columnDefs = list(list(width = '10px', targets = c(1,3)))))
output$applyplot <- renderPlotly(expr ={
g <- IAA.Applied() %>%
mutate(group = 1) %>%
ggplot(aes(Program, Applied_Act)) +
ylim(0,150)+
geom_col(fill = "#b0e0e6") +
geom_text(aes(label = Applied), position = position_dodge(0.3),family = "Times New Roman",size = 3)+
geom_col(aes(y = applied_Tar, group = group), color = "#e7e7e7" ,fill = "#A3A9D1", alpha=0.3) +
theme_classic()+
labs(x = "", y = "")
ggplotly(g, tooltip = "Applied")
})
output$processedplot <- renderPlotly(expr ={
g <- IA.processed() %>%
mutate(group = 1) %>%
ggplot(aes(Program, Act_Processed)) +
ylim(0,150)+
geom_col(fill = "#b0e0e6") +
geom_text(aes(label = Processed), position = position_dodge(0.3),family = "Times New Roman",size = 3)+
geom_col(aes(y = Tar_processed, group = group), color = "#e7e7e7" ,fill = "#A3A9D1", alpha=0.3) +
theme_classic()+
labs(x = "", y = "")
ggplotly(g, tooltip = "Processed")
})
#SmokeyShakers is right, Shiny is built so that the server side only renders when visible (i.e. you click on a tab or unhide a table).
I would look at the data you are pulling in and any data manipulation you are doing and seeing if that is the cause of the 30 seconds.
I would use the package profvis to do an analysis on your app.
If the data manipulation/reading is the cause there are multiple options such as running a separate process to do the data manipulation and putting the data into a global variable.

How to center table in box in Shiny Dashboard

I'm having difficulty centering a table I made in Shiny Dashboard within a box. I used a .csv file, but here is some fake data:
Stage = c("Survey", "Work Sample", "Interview", "Stats Test")
Score = c("+33.7%", "+14.8%", "+20.8%", "+28.17%")
no1_cand = data.frame(Stage, Score)
Score =c("+37.1%", "+14.2%", "+19.3%", "+26.3%")
no2_cand = data.frame(Stage, Score)
Score = c("+33.1%", "+22.2%", "+17.3%", "+25.8%")
no3_cand = data.frame(Stage, Score)
Score = c("+29.1%", "+17.2%", "+15.3%", "+23.3%")
no4_cand = data.frame(Stage, Score)
Score = c("+22.1%", "+12.5%", "+11.4%", "+19.5%")
no5_cand = data.frame(Stage, Score)
and the current code I have for the table and box:
#UI
box(title = "Top 5 Candidates",
status = "primary",
solidHeader = F,
collapsible = T,
width = 12,
fluidRow(
tableOutput('top5')))
#Server
output$top5 = renderTable({
top5_data
})
Currently it looks like this:
Try:
box(title = "Top 5 Candidates"
, status = "primary", solidHeader = F
, collapsible = T, width = 12
, column(12, align="center", tableOutput('top5')))

Right Side Bar handling in R Shiny

I am using library(ygdashboard) from here for build a Right Side control bar in Shiny Apps. Which most like AdminLTE.io template.
In AdminLTE.io Right Side Control Bar there is an option,by enabling it the content part will adjust the width and display accordingly.
Can any body help me out here?? My Try:
Mycode:
UI.R
library(shinydashboard)
library(shinyjs)
library(plotly)
library(shinyWidgets)
library(ygdashboard)
library(c3)
library(flexdashboard)
source("helper.R")
dashboardPage( skin = 'green',
dashboardHeader(title=" Test Stand Report",
tags$li(a(img(src = 'logo.jfif',
height = "30px"),
style = "padding-top:10px; padding-bottom:10px;"),
class = "dropdown")),
dashboardSidebar(sidebarMenu(id="tabs",
menuItem("DashBoard", tabName = "dashboard", icon = icon("dashboard", lib = "glyphicon")),
menuItem("Drill Report",icon = icon("link",lib = "glyphicon"),
menuSubItem("Test Stand",tabName = "test_stand",icon = icon("database")),
menuSubItem("Test Code",tabName = "test_code",icon = icon("folder-open",lib = "glyphicon")),
menuSubItem("Product Based",tabName = "product_based",icon = icon("database")),
menuSubItem("Time Shift",tabName = "time_shift",icon = icon("folder-open",lib = "glyphicon"))
)
)
),
dashboardBody(
shinyjs::useShinyjs(),
tabItems(
tabItem(tabName = "dashboard",
fluidRow(
column(3,
gaugeOutput("gauge1",width = "100%", height = "auto"),
uiOutput("infobox_1")
#gaugeOutput("gauge2",width = "100%", height = "auto")
),
column(3,
gaugeOutput("gauge3",width = "100%", height = "auto"),
uiOutput("infobox_2")
#gaugeOutput("gauge4",width = "100%", height = "100px")
),
column(3,
gaugeOutput("gauge5",width = "100%", height = "auto"),
uiOutput("infobox_3")
#gaugeOutput("gauge6",width = "100%", height = "auto")
),
column(3,
gaugeOutput("gauge7",width = "100%", height = "auto"),
uiOutput("infobox_4")
#gaugeOutput("gauge8",width = "100%", height = "auto")
)
),
fluidRow(
)
),
tabItem(tabName = "test_stand",
fluidRow(
column(3,
wellPanel(
uiOutput("test_stand_select")
)
),
column(3,uiOutput("count_test_code")),
column(3,uiOutput("count_vehicle_tested")),
column(3,uiOutput("count_vehicle_failed"))
),
fluidRow(
box(title = "Success Faliure Ratio",solidHeader = TRUE,width = 4,collapsible = TRUE,height = 'auto',status="success",
plotlyOutput("sucess_faliure_pie",height = '250px')
#tableOutput("sucess_faliure_pie")
),
box(title = "Success Faliure rate with Test_Code",solidHeader = TRUE,width = 8,collapsible = TRUE,height = 'auto',status="success",
#tableOutput("test_stand_test_code_rel")
plotlyOutput("test_stand_test_code_rel",height = '250px')
)
)
),
tabItem(tabName = 'test_code',
fluidRow(
)
)
)
),
dashboardFooter(mainText = "My footer", subText = "2018"),
dashboardControlbar()
)
Server.R
library(shiny)
library(shinyjs)
library(RMySQL)
library(DT)
library(devtools)
library(woe)
library(sqldf)
library(plyr)
library(shinyalert)
source("helper.R")
shinyServer(function(input, output,session) {
######################### Date range Selection ################################
output$date_range<-renderUI({
if(input$tabs=="test_stand")
{
dateRangeInput("selected_date_range_test_stand", "Select Time Period:",
start = Sys.Date()-10,
end = Sys.Date(),
max=Sys.Date())
}
else if(input$tabs=="test_code")
{
dateRangeInput("selected_date_range_test_code", "Select Time Period:",
start = Sys.Date()-10,
end = Sys.Date(),
max=Sys.Date())
}
else if(input$tabs=="product_based")
{
dateRangeInput("selected_date_range_product_based", "Select Time Period:",
start = Sys.Date()-10,
end = Sys.Date(),
max=Sys.Date())
}
})
##########################report buttom ################################
output$action_btn<-renderUI({
if(input$tabs=="test_stand")
{
actionBttn("get_data_test_stand","Get Report")
}
else if(input$tabs=="test_code")
{
actionBttn("get_data_test_code","Get Report")
}
else if(input$tabs=="product_based")
{
actionBttn("get_data_product_based","Get Report")
}
})
#########################product group selection##################################
output$pg_list<-renderUI({
if(input$tabs=="test_stand")
{
selectInput("selected_pg_test_stand","Select your Product Group",choices = c("Back"="BHO","SKD"="SKD","ABC"="ABC"))
}
else if(input$tabs=="test_code")
{
selectInput("selected_pg_test_code","Select your Product Group",choices = c("Back"="BHO","SKD"="SKD","ABC"="ABC"))
}
else if(input$tabs=="product_based")
{
selectInput("selected_pg_product_based","Select your Product Group",choices = c("Back"="BHO","SKD"="SKD","ABC"="ABC"))
}
})
#############################top 8 gauge################################
output$gauge1<-renderGauge({
gauge(0.5,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),label = 'Gauge 1')
})
output$infobox_1<-renderInfoBox({
infoBox("Total Test Stand Active",10 * 2,subtitle = "Subtitle", icon = icon("credit-card"),fill = TRUE,color = "yellow")
})
output$gauge3<-renderGauge({
gauge(0.7,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),label = 'Gauge 3')
})
output$infobox_2<-renderInfoBox({
infoBox("Total Test Code Running ",10 * 2,subtitle = "Subtitle" ,icon = shiny::icon("bar-chart"),color = "fuchsia",width = 4,fill = TRUE)
})
output$gauge5<-renderGauge({
gauge(0.6,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),label = 'Gauge 5')
})
output$infobox_3<-renderInfoBox({
infoBox(
"Total Vehicle Tested", "80%",subtitle = "Subtitle", icon = icon("list"),
color = "green", fill = TRUE
)
})
output$gauge7<-renderGauge({
gauge(0.3,
min = 0,
max = 1,
sectors = gaugeSectors(success = c(0.5, 1),
warning = c(0.3, 0.5),
danger = c(0, 0.3)),label = 'Gauge 7')
})
output$infobox_4<-renderInfoBox({
infoBox("Total Vehicle Passed ",10 * 2,subtitle = "Subtitle", icon = icon("check"),fill = TRUE, color = 'orange')
})
#############################test_stand value_box########################
})
Helper.R (from the link)
dashboardControlbar <- function() {
withTags(
div(
id = "right_sidebar",
# Control Sidebar Open
aside(class = "control-sidebar control-sidebar-dark",
# # # # # # # #
#
# Navigation tabs
#
# # # # # # # #
ul(class = "nav nav-tabs nav-justified control-sidebar-tabs",
# first tabs
li(class = "active",
a(href = "#control-sidebar-first-tab", `data-toggle` = "tab",
i(class = "fa fa-sliders")
)
),
# second tabs
li(
a(href = "#control-sidebar-second-tab", `data-toggle` = "tab",
i(class = "fa fa-search")
)
),
# third tab
li(
a(href = "#control-sidebar-third-tab", `data-toggle` = "tab",
i(class = "fa fa-paint-brush")
)
)
),
# # # # # # # #
#
# Tab Panels
#
# # # # # # # #
div(class = "tab-content",
#########################
# First tab content #
#########################
div(class = "tab-pane active", id = "control-sidebar-first-tab",
h3(class = "control-sidebar-heading", "Controller"),
# write elements here
uiOutput("date_range"),
#textOutput("date_validate"),
uiOutput("pg_list"),
uiOutput("action_btn")
#actionBttn("get_data","Get Report")
),
#########################
# Second tab content #
#########################
div(class = "tab-pane", id = "control-sidebar-second-tab",
h3(class = "control-sidebar-heading", "Search"),
# write other elements here
selectInput("selected_search_topic","Select Content Type to Seacrh",choices = c("Test Stand","Test Code","Product")),
searchInput("searchtext","Enter your Search Topic Here", placeholder = "A placeholder",btnSearch = icon("search"),btnReset = icon("remove"))
),
#########################
# Third tab content #
#########################
div(class = "tab-pane", id = "control-sidebar-third-tab",
# third tab elements here
radioButtons("dist", "Distribution type:",
c("Normal" = "norm",
"Uniform" = "unif",
"Log-normal" = "lnorm",
"Exponential" = "exp")
)
)
)
),
# control-sidebar
# Add the sidebar background. This div must be placed
# immediately after the control sidebar
div(class = "control-sidebar-bg", "")
)
)
}

Error in if (inline) { : argument is not interpretable as logical

This is related to another post I have, concerning adding a new fluidRow (conainting plot + selectInput) in my shinyDashboard app.
When I run the code below, I'm receiving the following
Error in if (inline) { : argument is not interpretable as logical
I've tried to tinker with the way the code is written, e.g. remove commas, but I've not been able to find a way to get rid of the error. What's more, I think it's one of the causes of not being able to generate an additional fluidrow.
I have a feeling its got something to do with my input controls, but no idea what!
Any help would be appreciated.
ui.r
ui <- dashboardPage(
skin = "red",
dashboardHeader(title = "iReport",
titleWidth = 500),
dashboardSidebar(),
dashboardBody(
tabItems(
# Tab for Dashboard
tabItem(tabName = "Dashboard"),
# Tab for Survey Analytics
tabItem(tabName = "Survey"),
#Tab for Enquiry Analytics
tabItem(tabName = "Enquiries"),
#Tab for Web Analytics
tabItem(tabName = "Metrics"),
#Tab for Twitter Analytics
tabItem(tabName = "Twitter")
),
# Row 1 objects
fluidRow(
# Value boxes
valueBox(
479,
"Total No. of Enquiries",
color = "green",
icon = icon("commenting")
),
valueBox(
1.7,
"Average response time",
color = "blue",
icon = icon("exchange")
),
valueBox(
"98%",
"Percentage satisfied customers",
color = "orange",
icon = icon("thumbs-up")
)
),
# Row 2 objects
fluidRow(box(
width = 12, plotlyOutput("Time_Ser", height = "400px")
)),
# Row 3 objects
fluidRow(
# Data visualisations 1
box(width = 5, plotlyOutput("Enq_Num", height = "500px")),
box(
width = 2,
h2("Control panel"),
dateRangeInput(
"date",
"Date:",
label = h4("Choose a time frame"),
start = "2017-05-02",
end = "2017-07-30",
min = "2017-05-02",
max = "2017-06-30",
startview = "2017-06-30"
),
selectInput(
"select",
"Select",
label = h4("Select a month"),
choices = c("May", "June")
),
radioButtons(
"area",
"Area",
label = h4("Response Time by Team"),
choices = list("PEU", "DAU", "MSU", "PRO", "MISC"),
selected = "PEU"
)),
box(width = 5, plotlyOutput("Response", height = "500px"))),
#Row 4 Objects
fluidRow(# Data visualisations 2
box(width = 5, plotlyOutput("Enq_Outcome")),
box(
width = 2,
selectInput(
"outcome",
"Outcome",
label = h4("Enquiry outcomes by output area"),
choices = list("Link", "Clarified", "CM", "Unavailable", "Referred")
)))))
server.r
server <- function(input, output) {
# Reactive date input for Tim_Ser
Time2 <- Time
reactiveTime <- reactive({
Time2 %>% filter(Date.received >= input$date[1] &
Date.received < input$date[2])})
# DATA
Numbers <-
data.frame(
May = c(73, 26, 23, 10, 23),
June = c(144, 28, 21, 20, 33),
areas = c("PEU", "MIG", "DAU", "MISC", "PRO")
)
Time <- CusTible %>% group_by(Date.received) %>% tally(sort = TRUE)
Time = Time[order(Time$Date.received), ]
Respond <-
data.frame(
DAU = c(32, 14, 8),
MIG = c(51, 7, 4),
MISC = c(42, 41, 3),
PEU = c(135, 16, 18),
PRO = c(32, 15, 2),
Days = c("1-2 Days", "3-4 Days", "5+ Days")
)
rownames(Respond) <- c("1-2 Days", "3-4 Days", "5+ Days")
Outcome <-
data.frame(
Area = c("DAU", "PEU", "PRO", "MSU", "MISC"),
CLAR = c(5, 23, 2, 2, 13),
LINK = c(45, 4, 23, 24, 18),
UNAV = c(1, 13, 15, 11, 12),
CM = c(8, 15, 3, 10, 2),
REF = c(26, 24, 11, 7, 12)
)
# OUTPUTS
output$Time_Ser <- renderPlotly({
Time_Ser <-
plot_ly(reactiveTime(),
x = Date.received,
y = n,
mode = "lines") %>%
layout(title = "Q3. Enquiries over Time")
})
output$Enq_Num <- renderPlotly({
selector <- switch(input$select,
"May" = Numbers$May,
"June" = Numbers$June)
Enq_Num <- plot_ly(
Numbers,
x = areas,
y = selector,
type = "bar",
color = areas
) %>%
layout(
title = "Q3. Enquiries by Output Team by Month",
xaxis = list(title = "Output Team", showgrid = F),
yaxis = list(title = "No. Enquiries")
)
})
output$Response <- renderPlotly({
if (is.null(input$area))
return()
area.select <- switch(
input$area,
"PEU" = Respond$PEU,
"DAU" = Respond$DAU,
"MSU" = Respond$MIG,
"PRO" = Respond$PRO,
"MISC" = Respond$MISC
)
Response <- plot_ly(
Respond,
labels = Days,
values = area.select,
type = "pie",
rotation = 180,
direction = "clockwise",
hole = 0.6
) %>%
layout(title = "Q3. Response Time")
})
output$Enq_Outcome <- renderPlotly({
enq.outcome <- switch(
input$outcome,
"Clarified" = Outcome$CLAR,
"Link" = Outcome$LINK,
"CM" = Outcome$CM,
"Unavailable" = Outcome$UNAV,
"Referred" = Outcome$REF
)
Enq_Outcome <- renderPlotly(
Outcome,
y = Area,
x = enq.outcome,
type = "bar",
colour = Area
)
})
}
shinyApp(ui, server)
So after much persistence and a lot of help from the expert,
I find all my problems come down to the radioButton() input selector:
I replace
radioButtons(
"area",
"Area",
label = h4("Response Time by Team"),
choices = list("PEU", "DAU", "MSU", "PRO", "MISC"),
selected = "PEU"
)),
with
selectInput(
"area",
"Area",
label = h4("Response Time by Team"),
choices = list("PEU", "DAU", "MSU", "PRO", "MISC"),
)),
And the code works perfectly fine, the error message disappears and the new plot and fluidRow are integrated into the Dashboard.

Resources