I'm making a shiny dashboard. But it seems my dashboard doesn't communicate with the server when infoBoxOutput is used. It doesn't even appear. Can someone kindly look into the following code and let me know the issue here.
If I just simply use Infobox, it prints info_box1 but doesn't communicate with the server. When infoBoxOutput is used even it doesn't show up in the dashboard body.
library(shiny)
library(shinydashboard)
library(shinyjs)
source("D:/Upwork/MAL/3rd-Data Visualization/RCodes/MalServer.R")
shinyUI <-
dashboardPage( title="Demo App",
dashboardHeader(title="Covid-19 Death Analysis",dropdownMenuOutput("msgOutput")
# dropdownMenu(type="message",
# messageItem(from="Finance Update", message = "We are on threshold"),
# messageItem(from = "Sales Update", message = "Sales are at 55%", icon=icon("bar-chart") , time="22:00"),
# messageItem(from="Sales Update",message = "Sales meeting at 6 PM on Monday", icon=icon("handshake-o"),time="03-22-2021")
# )
),
dashboardSidebar( width =320,useShinyjs(),
sidebarMenu(
width = 2,
dateRangeInput('dateRange',
label = 'Filter crimes by date',
start = as.Date('2019-01-01') , end = as.Date('2021-06-01')),
selectInput("var", label = "1. Select the quantitative Variable",
choices = c("place_of_death"=3,"Month Name"=11, "cause_of_death"=8), selected = 8),
radioButtons( "dist", "Enable or disable Grouping:",
c("Enable" = "enable",
"Disable" = "disable" ), inline=T),
selectInput("var2", label = "1. Select the quantitative Variable",
choices = c("cause_of_death"=8, "year"=7), selected = 7),
radioButtons( "CauseOfDeathRad", "Enable or disable Grouping:",
c("Covid" = "covid",
"Non-Covid" = "nonCovid" ,
"Both" = "both"), inline=T),
radioButtons( "DeathonYearRad", "Enable or disable Grouping:",
c(
"2020" = "2020" ,
"2021" = "2021",
"All" = "All"), inline=T)
)),
dashboardBody(
useShinyjs(),
#Second Row:
infoBoxOutput('info_box1'),
infoBox('Loading %', '0.97%', icon = icon('percent')),
infoBox('Revenue', 'R$ 60.000,00', icon = icon('dollar-sign')),
tabsetPanel(
#tabPanel("Plot", plotOutput("myhist")) ,
tabPanel("Plot2", plotOutput("myhist2"))
)
)
)
shinyServer <- function(input, output ) {
output$info_box1 <- renderInfoBox({
infoBox("Amount in Total here", sum(mydf$Amount))
})
}
shinyApp(shinyUI,shinyServer)
Related
I have the shiny app below with 3 different tabs, a sidebar and a right sidebar. I would like every time that I move to another tab the content of the two sidebars to change and display different widgets. In the commeted -out lines you can see the different widgets that I want to display.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shiny)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
sidebar = dashboardSidebar(minified = F, collapsed = F,
h4("Investment Selected"),
textInput("StockTicker", "Enter Stock Symbol", value = "NFLX")
#textInput("StockTicker2", "Enter Stock Symbol 2", value = "NFLX")
#textInput("StockTicker3", "Enter Stock Symbol 3", value = "NFLX")
),
body = dashboardBody(
h3('Results'),
tabsetPanel(
tabPanel("Insider Training"),
tabPanel("Switching"),
tabPanel("Tax Loss Harvesting")
)
),
controlbar = dashboardControlbar(width = 300,
h4("Insider Trading Parameters"),
selectInput("InsiderTradingModel", "Insider Trading Model",
c("Dynamic" = "Dynamic",
"AI based" = "AIbased"))
#selectInput("InsiderTradingModel2", "Insider Trading Model 2",
# c("Dynamic" = "Dynamic",
# "AI based" = "AIbased"))
#selectInput("InsiderTradingModel3", "Insider Trading Model 3",
# c("Dynamic" = "Dynamic",
# "AI based" = "AIbased"))
),
title = "DashboardPage"
)),
server = function(input, output) {
}
)
Perhaps you are looking for something like this
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
sidebar = dashboardSidebar(minified = F, collapsed = F,
h4("Investment Selected"),
uiOutput("mytab11"), uiOutput("mytab12")
#textInput("StockTicker3", "Enter Stock Symbol 3", value = "AMZN")
),
body = dashboardBody(
h3('Results'),
tabsetPanel(id = "tabs",
tabPanel("InsiderTraining"),
tabPanel("Switching"),
tabPanel("Tax Loss Harvesting")
)
),
controlbar = dashboardControlbar(width = 300,
h4("Insider Trading Parameters"),
uiOutput("mytab21"), uiOutput("mytab22")
#selectInput("InsiderTradingModel3", "Insider Trading Model 3",
# c("Dynamic" = "Dynamic",
# "AI based" = "AIbased"))
),
title = "DashboardPage"
)),
server = function(input, output) {
output$mytab11 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="InsiderTraining"',
textInput("StockTicker", "Enter Stock Symbol", value = "NFLX"),
sliderInput('periods','Periods',min=1,max=120,value=60),
selectInput("mtvar", "Choose a variable", choices = colnames(mtcars))
))
})
output$mytab12 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="Switching"',
textInput("StockTicker2", "Enter Stock Symbol", value = "APPL"),
selectInput("cvar", "Choose a variable", choices = colnames(cars))
))
})
output$mytab21 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="InsiderTraining"',
selectInput("InsiderTradingModel", "Insider Trading Model",
c("Dynamic" = "Dynamic",
"AI based" = "AIbased")),
#textInput("StockTicker", "Enter Stock Symbol", value = "NFLX"),
selectInput("ivar", "Choose a variable", choices = colnames(iris))
))
})
output$mytab22 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="Switching"',
selectInput("InsiderTradingModel2", "Insider Trading Model 2",
c("Dynamic" = "Dynamic",
"BI based" = "BIbased")),
sliderInput('periodss','Periods',min=1,max=100,value=30),
selectInput("pvar", "Choose a variable", choices = colnames(pressure))
))
})
}
)
Can someone please explain me the reason for having a big whitespace between following?
server = function(input, output){
# server code
}
ui = fluidPage(
fluidRow(
column(8, offset = 0, style='padding:0px;', # Sidebar panel
sidebarPanel(useShinyjs(),
dateRangeInput('dateRange',
label = 'Filter crimes by date',
start = as.Date('2019-01-01') , end = as.Date('2021-06-01')),
selectInput("var", label = "1. Select the quantitative Variable",
choices = c("place_of_death"=3,"Month Name"=11, "cause_of_death"=8), selected = 8),
radioButtons( "dist", "Enable or disable Grouping:",
c("Enable" = "enable",
"Disable" = "disable" ), inline=T),
selectInput("var2", label = "1. Select the quantitative Variable",
choices = c("cause_of_death"=8, "year"=7), selected = 7),
radioButtons( "CauseOfDeathRad", "Enable or disable Grouping:",
c("Covid" = "covid",
"Non-Covid" = "nonCovid" ,
"Both" = "both"), inline=T),
radioButtons( "DeathonYearRad", "Enable or disable Grouping:",
c(
"2020" = "2020" ,
"2021" = "2021",
"All" = "All"), inline=T)
)),
column(2, offset = 0, style='padding:0px;', wellPanel(p("Column width 2"))),
column(2, offset = 0, style='padding:0px;', wellPanel(p("Column width 2")))
)
)
shinyApp(ui = ui, server = server)
I need my dashboard to be equally divided among different plots. But this seems really hard to be done.
Appreciate if someone could help
PS.
When column(8,...) is set to column(3...)
My suggestion is to use the fluidRow() and column() in the mainPanel() to display the plots. Widgets for input can be kept in sidebarPanel(). Try this
server = function(input, output){
# server code
}
ui = fluidPage(
useShinyjs(),
sidebarLayout(
sidebarPanel(
dateRangeInput('dateRange',
label = 'Filter crimes by date',
start = as.Date('2019-01-01') , end = as.Date('2021-06-01')),
selectInput("var", label = "1. Select the quantitative Variable",
choices = c("place_of_death"=3,"Month Name"=11, "cause_of_death"=8), selected = 8),
radioButtons( "dist", "Enable or disable Grouping:",
c("Enable" = "enable",
"Disable" = "disable" ), inline=T),
selectInput("var2", label = "1. Select the quantitative Variable",
choices = c("cause_of_death"=8, "year"=7), selected = 7),
radioButtons( "CauseOfDeathRad", "Enable or disable Grouping:",
c("Covid" = "covid",
"Non-Covid" = "nonCovid" ,
"Both" = "both"), inline=T),
radioButtons( "DeathonYearRad", "Enable or disable Grouping:",
c(
"2020" = "2020" ,
"2021" = "2021",
"All" = "All"), inline=T)
),
mainPanel(
fluidRow(
column(5, offset = 0, style='padding:0px;', wellPanel(p("Column width 5"))),
column(5, offset = 0, style='padding:0px;', wellPanel(p("Column width 5")))
)
)
)
)
shinyApp(ui = ui, server = server)
I have a reproducible example below where only the first tabPanel is working, however when I switch to another panel, I don't get any renders (the toggle becomes un-interactable also). I have looked into conditionalPanel however I see them getting done without the use of mainPanel I was wondering if it possible to have tabs where each tab has its own mainPanel , so I can see a different sidebar and an output contained within different tabs. Any help is welcome!
options(scipen = 99999) #converts the sci numbers to their regular format
library(shiny)
library(shinyjs)
library(shinyWidgets)
library(shinyalert)
library(esquisse)
library(DT)
library(dplyr)
#library(devtools)
#library(remotes)
#remotes::install_github("dreamRs/esquisse")
library(hrbrthemes)
library(ggthemes)
library(ggplot2)
library(svglite)
ui <- fluidPage(
shinyjs::useShinyjs(), # enables javascript/jQuery enhanchments
# Create Right Side Text
navbarPage(
title= div(HTML("G<em>T</em>")),
#General reports
tabPanel("General Reports",
shinyWidgets::materialSwitch(inputId = "toggleSidebar", label = "Toggle Panel: ",
value = TRUE, status = "warning"),
sidebarLayout(
# radio/action buttons
sidebarPanel(
id = "Sidebar",
shinyWidgets::prettyRadioButtons(
inputId = "controller",
label = "Choose:",
choices = c("About"= 1,
"iris"= 2),
icon= icon("check"),
selected = 1,
status = "success",
animation="smooth"
),
br(),
br(),
a(actionButton(inputId = "admin_email", label = "Contact",
icon = icon("envelope", lib = "font-awesome")),
href="mailto:xyz#email.us")
),
#panel where output is shown from server
mainPanel(
id = "main_panel",
tabsetPanel(
id = "hidden_tabs",
type = "hidden",
tabPanelBody(
"panel1", "Text coming soon."
),
tabPanelBody(
"panel2",
tabsetPanel(
tabPanel("Data", DT::DTOutput('panel2_data')),
tabPanel(
"DIY Plot",
esquisse::esquisse_ui(
id = "esquisse2",
header = FALSE,
container = esquisseContainer(
width = "100%", height = "760px", fixed = FALSE
),
controls = c("labs", "parameters", "appearance", "filters", "code")
)
)
)
)
)
)
)
),
# monthly reports
tabPanel("Extra General Reports",
shinyWidgets::materialSwitch(inputId = "toggleSidebar", label = "Toggle Panel: ",
value = TRUE, status = "warning"),
sidebarLayout(
# radio/action buttons
sidebarPanel(
id = "Sidebar",
shinyWidgets::prettyRadioButtons(
inputId = "controller",
label = "Choose:",
choices = c("About"= 3,
"mtcars"= 4),
icon= icon("check"),
selected = 3,
status = "success",
animation="smooth"
),
br(),
br(),
a(actionButton(inputId = "admin_email", label = "Contact",
icon = icon("envelope", lib = "font-awesome")),
href="mailto:xyz#email.us")
),
#panel where output is shown from server
mainPanel(
id = "main_panel",
tabsetPanel(
id = "hidden_tabs",
type = "hidden",
tabPanelBody(
"panel3", "Text coming soon."
),
tabPanelBody(
"panel4",
tabsetPanel(
tabPanel("Data", DT::DTOutput('panel4_data')),
tabPanel(
"DIY Plot",
esquisse::esquisse_ui(
id = "esquisse4",
header = FALSE,
container = esquisseContainer(
width = "100%", height = "760px", fixed = FALSE
),
controls = c("labs", "parameters", "appearance", "filters", "code")
)
)
)
)
)
)
)
),
#resizes the navbar tabs/button
tags$head(tags$style(HTML('.navbar-brand {width: 270px; font-size:35px; text-align:left;
font-family: "serif";')))
)
)
server <- function(input, output, session) {
# this event hides the side panel when toggled on/off
observeEvent(input$toggleSidebar, {
shinyjs::toggle(id = "Sidebar", condition = input$toggleSidebar)
if(!isTRUE(input$toggleSidebar)) {
shinyjs::runjs("$('#main_panel').removeClass('col-sm-8').addClass('col-sm-12')")
} else {
shinyjs::runjs("$('#main_panel').removeClass('col-sm-12').addClass('col-sm-8')")
}
})
# here we put all the data
data_sets <- list(df1 = data.frame(),
df2 = iris,
df3 = data.frame(),
df4 = mtcars)
# store current dataset in reactive so we can work with plot panels
data_to_use <- reactiveValues(name = "df", data = data.frame())
# modules only need to be called it once but individually for esquisse
esquisse::esquisse_server(id = "esquisse2", data_rv = data_to_use)
esquisse::esquisse_server(id = "esquisse4", data_rv = data_to_use)
observeEvent(input$controller, {
# skip first panel since it is used to display navigation
updateTabsetPanel(session, inputId= "hidden_tabs", selected = paste0("panel", input$controller))
# enswure value is avilable throught selected tabSet
req(input$controller)
# get current data and df name
data_to_use$data <- data_sets[[as.numeric(input$controller)]]
data_to_use$name <- names(data_sets[as.numeric(input$controller)])
# update table and sum. Use server = FALSE to get full table
output[[paste0('panel', input$controller, '_data')]] <- DT::renderDT(server = FALSE, {
DT::datatable(data_to_use$data,
filter = 'top',
extensions = 'Buttons')})
})
}
#runs the app
shinyApp(ui= ui, server= server)
You have two radioButtons, one for each sidebar, but both of them have the inputId = "controller". Same with inputId = "toggleSidebar". InputIds need to be unique in shiny!
I suggest you either use a single sidebar for the entire app, or since both tabs are essentially identical you can also use modules.
I have the shinydashboard below in which I have 3 tabPanels. In the 1st tabPanel "Resource Allocation" I want the left and right sidebar open by default. In the 2nd and 3rd tabpanels ("Time Series","Longitudinal View") I want only left sidebar and the right sidebar not just hidden but to not be able to open at all by pushing the "gears" icon above it which should be removed. And in the fourth panel "User Guide" I want no sidebar and no choise to open one of them at all.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
shinyApp(
ui = dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(
titleWidth = "0px"
),
sidebar = dashboardSidebar(minified = TRUE, collapsed = F),
body = dashboardBody(
useShinyjs(),#tags$head(tags$script(src="format_number.js")),
tags$script("document.getElementsByClassName('sidebar-toggle')[0].style.visibility = 'hidden';"),
tabsetPanel(
tabPanel("Resource Allocation"),
tabPanel("Time Series"),
tabPanel("Longitudinal View"),
tabPanel("User Guide")
)
),
controlbar = dashboardControlbar(collapsed = F),
title = "DashboardPage"
),
server = function(input, output) { }
)
I have a solution for the left sidebar. I am sure you can spend sometime and figure out the solution for the right sidebar. Please note that this requires some more work to fine tune to your needs. Try this
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
library(DT)
ui <- shinydashboardPlus::dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
shinydashboardPlus::dashboardHeader(
#titleWidth = "0px"
),
shinydashboardPlus::dashboardSidebar( disable = TRUE ,
sidebarMenu(
selectInput(
"countries", label = "Select Countries",
choices = c("B", "C", "A"), selected = "A",
multiple = TRUE
))
),# minified = TRUE, collapsed = F),
controlbar = shinydashboardPlus::dashboardControlbar(id = "controlbar", collapsed = F,
skin = "dark",
controlbarMenu(
id = "menu",
controlbarItem(
"Tab 1",
"Welcome to tab 1"
),
controlbarItem(
"Tab 2",
"Welcome to tab 2"
)
)
),
shinydashboard::dashboardBody(
useShinyjs(),
tabsetPanel( id="tabset",
tabPanel("Resource Allocation", value="tab1", plotOutput("plot")),
tabPanel("Time Series", value="tab2", plotOutput("plot2")),
tabPanel("Longitudinal View", value="tab3", DTOutput("ir")),
tabPanel("User Guide", value="tab4", DTOutput("mt"))
)
),
# controlbar = dashboardControlbar(collapsed = F),
title = "DashboardPage"
)
server <- function(input, output) {
output$plot <- renderPlot(plot(cars))
output$plot2 <- renderPlot(plot(pressure))
output$mt <- renderDT(mtcars)
output$ir <- renderDT(iris)
observeEvent(input[["tabset"]], {
if(input[["tabset"]] == "tab4"){
addClass(selector = "body", class = "sidebar-collapse")
updateControlbar("controlbar")
}else{
removeClass(selector = "body", class = "sidebar-collapse")
}
})
}
shinyApp(ui, server)
In the given R shiny script below, I am trying to use a conditional panel with Picker Input shiny widget. There are three options in pickerInput, upon selection of "times" option, I wish to create new pickerInputs using a conditional panel, the following is possible using selectInput, but I need the same for Picker Input. Thanks and please help.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Picket",titleWidth = 290),
dashboardSidebar(width = 0),
dashboardBody(
tabsetPanel(type = "tab",
tabPanel("Overview", value = 1,
box(
column(1,
dropdown(
pickerInput(inputId = "resources",
label = "",
choices = c("cases",
"activities",
"times"),
choicesOpt = list(icon = c("fa fa-bars",
"fa fa-bars",
"fa fa-safari")),
options = list(`icon-base` = "")),
circle = FALSE, status = "primary", icon = icon("list", lib = "glyphicon"), width = "300px"
),
conditionalPanel(
condition = "input.Position == 'times' ",
dropdown(
pickerInput(inputId = "Id072",
label = "Select/deselect all options",
choices = c("A","Check-out", "b","c","d","e","f")
)))))),
id= "tabselected"
)
))
server <- function(input, output) {
}
shinyApp(ui, server)
Shouldnt this condition = "input.Position == 'times' ", be condition = "input.resources == 'times' ",?