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.
Related
I have shiny dashboard with two tabPanels. First tabpanel having infoboxes with date range selection and second one with radiobuttons selection for infoboxes. Second one with radiobuttons working fine when date range selection is not there is first tabpanel. But when I adding date range selection to the first tabpanel, then radiobuttons are not functioning in second tabpanel. Why does the radiobuttons are not functioning while adding date range select feature in first "tabpanel"?
Here is my code:
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
dat1 <- data.frame(
name = c("Male", "Female"),
value = c(10, 20)
)
dat2 <- data.frame(
name = c("Male", "Female"),
value = c(30, 40)
)
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "123"),
dashboardSidebar(disable = TRUE),
dashboardBody(fluidPage(
tabsetPanel(
tabPanel(h5("Beneficiaries"),
fluidRow(radioButtons("Bene", "Details", c("Vis","Scre", "Sus"), inline = T),
infoBoxOutput("loc", width = 960),
loadEChartsLibrary(),
tags$div(id="test5", style="width:60%;height:300px;"),
deliverChart(div_id = "test5"), width = "800px", height = "400px")),
tabPanel(h5("summary"),
box(
infoBoxOutput("first", width = 6),
infoBoxOutput("second", width = 6), width = 8
),
box(h4("Date selection"), dateRangeInput("dateRange", "Select date range:", width =
200, submitButton(text = "Submit", icon = NULL, width = 4))
)
)
))))
server <- shinyServer(function(input,output){
output$loc <- renderInfoBox({
if (input$Ben == "Vis"){
box(h3("Vis"),
infoBox("Total", 1, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE),
background = "black")
}
else {if (input$Ben == "Scre") {
box(h3("Scre"),
infoBox("Total", 2, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat2, show.label = TRUE),
background = "black")
}
else{ box(h3("Sus"),
infoBox("Full", 3, width = 12)
)
} }}
})
})
shinyApp(ui,server)
Can anyone help on this?
Thanks a lot in advance.
Updated answer
I made some corrections to your code (there were some issues with the curly braces in you if/else statement). Not sure if that is what you intended.
library(shiny)
library(shinydashboard)
library(ECharts2Shiny)
dat1 <- data.frame(
name = c("Male", "Female"),
value = c(10, 20)
)
dat2 <- data.frame(
name = c("Male", "Female"),
value = c(30, 40)
)
ui <- shinyUI(dashboardPage(
dashboardHeader(title = "123"),
dashboardSidebar(disable = TRUE),
dashboardBody(fluidPage(
tabsetPanel(
tabPanel(h5("Beneficiaries"),
fluidRow(radioButtons("Ben", "Details", c("Vis","Scre", "Sus"), inline = T),
infoBoxOutput("loc", width = 960),
loadEChartsLibrary(),
tags$div(id = "test5", style="width:60%;height:300px;"),
deliverChart(div_id = "test5"), width = "800px", height = "400px")),
tabPanel(h5("summary"),
box(
infoBoxOutput("first", width = 6),
infoBoxOutput("second", width = 6), width = 8
),
box(h4("Date selection"), dateRangeInput("dateRange",
"Select date range:",
width = 200,
submitButton(text = "Submit", icon = NULL, width = 4)))
)
)
))))
server <- shinyServer(function(input,output){
output$loc <- renderInfoBox({
if (input$Ben == "Vis"){
box(h3("Vis"),
infoBox("Total", 1, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat1, show.label = TRUE),
background = "black")
} else if (input$Ben == "Scre") {
box(h3("Scre"),
infoBox("Total", 2, width = 4),
infoBox("part", 1, width = 4),
renderPieChart(div_id = "test1", data = dat2, show.label = TRUE),
background = "black")
} else { box(h3("Sus"),
infoBox("Full", 3, width = 12))
}
})
})
shinyApp(ui,server)
I have a table being display in a shiny app. I want to format the tables based on the values and color it accordingly. I have seen the formattable area coloring where based on the range of the values it defines the breaks and then color gradients are generated which are applied to the table. What I want to do is allow the user to fill the min and max value and depending on it the values in the table will be colored. So if the values range from 1-20 and if the user inputs are 5 and 15 , values below 5 and above 15 shouldnt have any color gradients applied to them. Below is the code of how I am doing currently using formatable area formatting.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow( column(
width = 3, textInput("text1", label = h5("Min"), value = "Enter min")),
column(
width = 3, textInput("text2", label = h5("Max"), value = "Enter max"))),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda civic","honda accord"),
april = c(.1,.2,.3,.3,.4,.5),
may = c(.3,.4,.5,.2,.1,.5),
june = c(.2,.1,.5,.1,.2,.3))
brks <- reactive({ quantile(df$april, probs = seq(.05, .95, .05), na.rm = TRUE)})
clrs <- reactive({ round(seq(255, 175, length.out = length(brks()) + 1), 0) %>%
{paste0("rgb(",.,",", ., ",255 )")}})
df_format<- reactive ({datatable(df,options = list(searching = FALSE,pageLength = 15, lengthChange = FALSE))%>%
formatStyle(names(df),backgroundColor = styleInterval(brks(), clrs()))})
output$op <-renderDataTable({
df_format()
})
}
shinyApp(ui = ui, server = server)
Here is your working code.
You must use that input minimal and maximal value as limits for your sequence (I just change it to range - is easier for user to put a range like that)
Then you generate sequence - according your notation - brks() - in my case I use length.out of 10 but you can put as many breaks as you want or dynamically.
Then generate on
number of colors - 1
and in the end in styleInterval() for background add limits of white - or any other color you want.
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)
sidebar <- dashboardSidebar(
sidebarMenu(id = "tab",
menuItem("1", tabName = "1")
)
)
body <- ## Body content
dashboardBody(box(width = 12,fluidRow(
fluidRow(column(
width = 3,
sliderInput("range_value",
label = h3("Put a range value"),
min = 0,
max = 100,
value = c(5, 15)
)
)
),
DT::dataTableOutput("op")
)))
ui <- dashboardPage(dashboardHeader(title = "Scorecard"),
sidebar,
body)
# Define the server code
server <- function(input, output,session) {
df <- data.frame(month = c("mazda 3", "mazda cx5", "mazda 6","mazda miata","honda
civic","honda accord"),
april = c(9, 8, 11,14,16,1),
may = c(3,4,15,12,11, 19),
june = c(2,11,9,7,14,1))
brks <- reactive({
seq(input$range_value[1], input$range_value[2], length.out = 10)
})
clrs <- reactive({ round(seq(255, 175, length.out = length(brks()) - 1), 0) %>%
{paste0("rgb(",.,",", ., ",255)")}})
df_format<- reactive ({datatable(df,options = list(searching = FALSE, pageLength = 15, lengthChange = FALSE)) %>%
formatStyle(names(df),
backgroundColor = styleInterval(c(brks()), c('white', clrs() ,'white'))
)
})
output$op <-renderDataTable({
df_format()
})
}
shinyApp(ui = ui, server = server)
This question already has answers here:
Sort (order) data frame rows by multiple columns
(19 answers)
Closed 4 years ago.
I created a shiny app and need some help with the subset of my data. I insert a dateRangeInput where the client can filter between a start and end date. This filter is included into my ggplot code, so that the plot always automatically changes when a different date is selected. My problem is it does not filter based on the selected date, the data of partC. The problem is this line of code: geom_line(aes(x = Date, y = OLS.Data[partC]), color="red"). partC is a variable that connects to selectinputs to have access to my dataframe. Example: Client selects input1 = Informed and input2 = Full, partC makes InformedFull (which is the name of one column of my dataset) and so on. So partC is just a a connector of the two inputs, and this is my problem. If I put into my geom_line this code e.g geom_line(aes(x = Date, y = InformedFull), color="red"), instead the above everything works perfect, but I need it with partC.
Here is my ui.R code (only necessary part):
box(
title = "Controls-0",
status = "primary",
solidHeader = TRUE,
width = 3,
height = 142,
dateRangeInput("daterange", "SELECT DATE:", start = min(OLS.Data$Date), end = max(OLS.Data$Date))
),
box(
title = "Investor Control",
status = "primary",
solidHeader = TRUE,
width = 3,
selectInput("investor", label="Select Investor", choices = list("Informed" = "Informed", "Noise" = "Noise"), selected = "Informed")
),
box(
title = "Category Control",
status = "primary",
solidHeader = TRUE,
width = 3,
selectInput("category", label="Select Category", choices = list("Full" = "Full", "Fact" = "Fact", "Fact Positive" = "Fact.Pos", "Fact Negative" = "Fact.Neg", "Emotions" = "Emotions", "Emotions Fact" = "EmotionsFact"), selected = "Full")
),
Update server.R with ggplot:
server <- function(input, output) {
partC = NULL
makeReactiveBinding("partC")
observeEvent(input$investor, {
partA<<-input$investor
partA<<-as.character(partA)
})
observeEvent(input$category, {
partB<<-input$category
partB<<-as.character(partB)
})
OLS.Data$InformedEmotionsFact <- as.numeric(as.character(OLS.Data$InformedEmotionsFact))
OLS.Data$NoiseEmotionsFact <- as.numeric(as.character(OLS.Data$NoiseEmotionsFact))
output$myPlotVisu <- renderPlot({
partC<-as.character(paste(partA,partB,sep=""))
OLS.Data %>%
select(partC, NYSE,Date,Sector) %>%
filter(Date >= input$daterange[1], Date <= input$daterange[2]) %>%
ggplot(aes(x = Date, y = NYSE)) +
geom_line() +
ggtitle(paste(input$investor,input$category,sep = "")) +
theme(plot.title = element_text(hjust = 0.5,face="bold")) +
labs(x="Time",y="Return S&P500") +
geom_line(aes(x = Date, y = OLS.Data[partC]), color="red")
})
I dont know why you assign partA/partB to the global environment, and even twice. You dont need to do that. I created an reactiveValues object instead, where you store the values (partA, partB and partC). Then you can use them wherever you want in your app.
Maybe the following example will help you with your code. I created some dummy data for it.
library(shiny)
library(shinydashboard)
library(ggplot2)
## DATA #######################
DateSeq = seq(as.Date("1910/1/1"), as.Date("1911/1/1"), "days")
OLS.Data = data.frame(
ID = 1:length(DateSeq),
Date = DateSeq,
NoiseEmotionsFact = sample(1:100,length(DateSeq), T),
InformedEmotionsFact = sample(100:1000,length(DateSeq), T),
InformedFull = sample(10:1000,length(DateSeq), T),
NoiseFull = sample(50:5000,length(DateSeq), T),
NoiseFact = sample(1:15,length(DateSeq), T),
NoiseFact.Pos = sample(100:110,length(DateSeq), T),
NoiseFact.Pos = sample(10:200,length(DateSeq), T)
)
## UI #######################
ui <- {dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
plotOutput("myPlot"),
box(
title = "Controls-0",
status = "primary",
solidHeader = TRUE,
width = 3,
height = 142,
dateRangeInput("daterange", "SELECT DATE:", start = min(OLS.Data$Date), end = max(OLS.Data$Date))
),
box(
title = "Alpha",
sliderInput("alphaVisu", label = "Alpha :", min = 0, max = 1, value = 0.4, step = 0.1)
),
box(
title = "Investor Control",
status = "primary",
solidHeader = TRUE,
width = 3,
selectInput("investor", label="Select Investor",
choices = list("Informed" = "Informed", "Noise" = "Noise"), selected = "Informed")
),
box(
title = "Category Control",
status = "primary",
solidHeader = TRUE,
width = 3,
selectInput("category", label="Select Category",
choices = list("Full" = "Full", "Fact" = "Fact", "Fact Positive" = "Fact.Pos",
"Fact Negative" = "Fact.Neg", "Emotions" = "Emotions",
"Emotions Fact" = "EmotionsFact"), selected = "Full")
)
)
)}
## SERVER #######################
server <- function(input, output) {
## Reactive Values ############
parts <- reactiveValues(partA=NULL, partB=NULL, partC=NULL)
## Observe Events ############
observeEvent(input$investor, {
parts$partA <- as.character(input$investor)
})
observeEvent(input$category, {
parts$partB <- as.character(input$category)
})
## Plot ############
output$myPlot <- renderPlot({
parts$partC <- as.character(paste(parts$partA, parts$partB,sep=""))
OLS.Data.filtered <- OLS.Data %>%
filter(Date >= input$daterange[1], Date <= input$daterange[2])
req(OLS.Data.filtered)
OLS.Data.filtered %>%
ggplot(aes(x = Date, y = ID)) +
geom_line() +
ggtitle(paste("input$investor","input$category",sep = "")) +
theme(plot.title = element_text(hjust = 0.5,face="bold")) +
labs(x="Time",y="Return S&P500") +
geom_line(aes(x = Date, y = OLS.Data.filtered[parts$partC]), color="red",
alpha = rep(as.numeric(input$alphaVisu), nrow(OLS.Data.filtered[parts$partC])))
})
}
shinyApp(ui, server)
I have a leaflet map in my main panel and I want to place a dygraph inside an absolutePanel within an R shiny app.
My problem is that I can't see the dygraph inside the absolutePanel.
The code in my ui.R is like this:
library(dygraphs)
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
width = 300, height = "auto",
h2("Sensitivity Explorer"),
sliderInput(inputId="year",
label="Select a forecast year",
value=2018, min=2018, max=2050),
numericInput("months", label = "Months to Predict",
value = 72, min = 12, max = 144, step = 12),
selectInput("interval", label = "Prediction Interval",
choices = c("0.80", "0.90", "0.95", "0.99"),
selected = "0.95"),
checkboxInput("showgrid", label = "Show Grid", value = TRUE),
dygraphOutput("dygraph",width = '50%')
)
and my server.R :
library(dygraphs)
function(input, output, session) {
predicted <- reactive({
hw <- HoltWinters(ldeaths)
predict(hw, n.ahead = input$months,
prediction.interval = TRUE,
level = as.numeric(input$interval))
})
output$dyngraph <- renderDygraph({
if (nrow(zipsInBounds()) == 0)
return(NULL)
dygraph(predicted(), main = "Predicted Deaths/Month") %>%
dySeries(c("lwr", "fit", "upr"), label = "Deaths") %>%
dyOptions(drawGrid = input$showgrid)
})
}
Make sure you test for null first, also make use of req to find out how it works just type?req. Also its dyngraph btw
rm(list = ls())
library(shiny)
library(dygraphs)
ui <- fluidPage(
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
width = 300, height = "auto",
h2("Sensitivity Explorer"),
sliderInput(inputId="year",
label="Select a forecast year",
value=2018, min=2018, max=2050),
numericInput("months", label = "Months to Predict",
value = 72, min = 12, max = 144, step = 12),
selectInput("interval", label = "Prediction Interval",
choices = c("0.80", "0.90", "0.95", "0.99"),
selected = "0.95"),
checkboxInput("showgrid", label = "Show Grid", value = TRUE),
dygraphOutput("dyngraph",width = '50%')
)
)
server <- function(input, output, session){
zipsInBounds <- reactive({mtcars[0,0]})
predicted <- reactive({
req(input$interval)
req(input$months)
hw <- HoltWinters(ldeaths)
predict(hw, n.ahead = as.numeric(input$months),
prediction.interval = TRUE,
level = as.numeric(input$interval))
})
output$dyngraph <- renderDygraph({
if (is.null(zipsInBounds()))
return()
dygraph(predicted(), main = "Predicted Deaths/Month") %>%
dySeries(c("lwr", "fit", "upr"), label = "Deaths") %>%
dyOptions(drawGrid = input$showgrid)
})
}
shinyApp(ui = ui, server=server)
Got a few really tedious issue with Shiny Dashboard.
So, I've got three main plots and a input control panel, which span 2 fluidRows. I want to add another plot (Enq_Outcome) in a separate fluidRow, but having troubles displaying it in the viewer when loading the app.
In fact, there doesn't actually appear to be any problems with the code (at least R is not flagging it up when I run the code) and the rest of the app appears to load properly without any error messages (most of it anyway). So I'm not entirely sure why my new plot (Enq_Outcome) is not appearing.
In addition to this, two of my plots (Time_Ser) and (Response) don't initiate the default plot when loading the app, e.g. so the selected = " " argument doesn't appear to work for my radioButtons and dateRangeInput inputs.
Any help with this would be great as it's been puzzling me for ages.
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 <- data.frame(date = c("2017-05-02","2017-05-03","2017-05-04", "2017-05-05","2017-05-07"), n = c(14,11,7,12,14))
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
)
})
}
Run App
shinyApp(ui, server)