Shiny - Plotly output not appearing in viewer - r

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)

Related

Why radio buttons are not working with date input selection in two different tabPanel()s (shiny app)?

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)

Format table output in R shiny based on user inputs

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)

Subset Dataframe and plot with ggplot? [duplicate]

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)

Updating multiple infobox using plotly_click in R and plotly

If you please run the script, it gives you a basic Sankey Chart in R and plotly and a data table besides. Also, there are three infoBoxes on top. When I click on the Sankey lines in the plot, I see the value in the data table using plotly_click. I want a functionality when I click on any Sankey Line, it picks "pointNumber" Column value in the data table and then multiplies by 2 and put in first infobox, by 3 in second infobox, and multiply by 4 in third infobox as in the snap attached. Thanks and please help.
## app.R ##
library(shiny)
library(shinydashboard)
library(devtools)
library(ggplot2)
library(plotly)
library(proto)
library(RColorBrewer)
library(gapminder)
library(stringr)
library(broom)
library(mnormt)
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Multiple hover"),
dashboardSidebar(
width = 0
),
dashboardBody(
infoBox("Multiply by 2", 2 * 2, icon = icon("credit-card")),
infoBox("Multiply by 3", 2 * 3, icon = icon("credit-card")),
infoBox("Multiply by 4", 2 * 4, icon = icon("credit-card")),
tags$br(),
box(title = "Sankey Chart", status = "primary",height = "455" ,solidHeader =
T,
plotlyOutput("sankey_plot")),
box( title = "Case Summary", status = "primary", height = "455",solidHeader
= T,
dataTableOutput("sankey_table"))
)
)
server <- function(input, output)
{
output$sankey_plot <- renderPlotly({
trace1 <- list(
domain = list(
x = c(0, 1),
y = c(0, 1)
),
link = list(
label = c("Case1", "Case2", "Case3", "Case4", "Case5", "Case6",
"Case7"),
source = c(0, 1, 2, 3, 4, 5, 6, 7),
target = c(11, 12, 7, 10, 13, 9, 8),
value = c(5, 6, 2, 4, 10, 6, 2)
),
node = list(label = c("R1", "R2", "R3","R4","R5","R6","R7","Blood
Test","Check Out","Discuss Results",
"MRI Scan", "Registration", "Triage and Assessment",
"X-RAY")),
type = "sankey"
)
data <- list(trace1)
p <- plot_ly()
p <- add_trace(p, domain=trace1$domain, link=trace1$link,
node=trace1$node, type=trace1$type)
p
})
output$sankey_table <- renderDataTable({
d <- event_data("plotly_click")
if(is.null(d))
{
print("Hello, Please hover to see the result" )
} else
d
})
}
shinyApp(ui, server)
Considering event_data() outputs a dataframe, the below code access that particular value pointNumber and renders dynamic UI.
Code:
## app.R ##
library(shiny)
library(shinydashboard)
library(devtools)
library(ggplot2)
library(plotly)
library(proto)
library(RColorBrewer)
library(gapminder)
library(stringr)
library(broom)
library(mnormt)
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Multiple hover"),
dashboardSidebar(
width = 0
),
dashboardBody(
uiOutput('box1'),
tags$br(),
box(title = "Sankey Chart", status = "primary",height = "455" ,solidHeader =
T,
plotlyOutput("sankey_plot")),
box( title = "Case Summary", status = "primary", height = "455",solidHeader
= T,
dataTableOutput("sankey_table"))
)
)
server <- function(input, output)
{
output$sankey_plot <- renderPlotly({
trace1 <- list(
domain = list(
x = c(0, 1),
y = c(0, 1)
),
link = list(
label = c("Case1", "Case2", "Case3", "Case4", "Case5", "Case6",
"Case7"),
source = c(0, 1, 2, 3, 4, 5, 6, 7),
target = c(11, 12, 7, 10, 13, 9, 8),
value = c(5, 6, 2, 4, 10, 6, 2)
),
node = list(label = c("R1", "R2", "R3","R4","R5","R6","R7","Blood
Test","Check Out","Discuss Results",
"MRI Scan", "Registration", "Triage and Assessment",
"X-RAY")),
type = "sankey"
)
data <- list(trace1)
p <- plot_ly()
p <- add_trace(p, domain=trace1$domain, link=trace1$link,
node=trace1$node, type=trace1$type)
p
})
output$sankey_table <- renderDataTable({
d <- event_data("plotly_click")
if(is.null(d))
{
print("Hello, Please hover to see the result" )
} else
d
})
output$box1 <- renderUI({
tagList(
infoBox("Multiply by 2", event_data("plotly_click")$pointNumber * 2, icon = icon("credit-card")),
infoBox("Multiply by 3", event_data("plotly_click")$pointNumber * 3, icon = icon("credit-card")),
infoBox("Multiply by 4", event_data("plotly_click")$pointNumber * 4, icon = icon("credit-card"))
)
})
}
shinyApp(ui, server)
Screenshot:

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