So I've learned from my teammates that the server side of a RShiny app doesn't need to be completed for the UI side of an app to be shown.
Here's a bit of my code:
ui <- dashboardPage(
dashboardHeader(title = "Enrolment Analytics"),
dashboardSidebar(sidebarMenu(
#can change tab names and icons here.
menuItem("Summary Tables", tabName = "Summary Tables", icon = icon("table")),
menuItem("Visualizations", tabName = "Visualizations", icon = icon("line-chart"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "Summary Tables",
fluidRow(
box(title = "Teaching Load ", status = "primary", solidHeader = TRUE,
selectInput("courseCode1", "Course code: ",
choices = as.list(unique(data1$discipline))),
numericInput("Month", "1 = January, 2 = February, ..., 12 = December", value = 6),
numericInput("Year", "2007, 2008, ..., 2017", value = 2007)
),
box(title = "Summary ", status = "primary", solidHeader = TRUE,
plotOutput("tl1"))
))
),
tabItem(tabName = "Visualizations",
fluidRow(
box(title = "Teaching Load", status = "primary", solidHeader = TRUE,
selectInput("courseCodeOne", "First discipline: ",
choices = as.list(unique(data1$discipline))),
selectInput("courseCodeTwo", "Second discipline: ",
choices = as.list(unique(data1$discipline))),
selectInput("courseCodeThree", "Third discipline: ",
choices = as.list(unique(data1$discipline)))
),
box(title = "Teaching Load Graph", status = "primary", solidHeader = TRUE,
plotOutput("tl2"))
))
)
)
When I run the app, the sidebar shows Visualizations and Summary Tables but on the server side of things, only the visualizations boxes show up and the summary tables do not.
There were two issues with your code:
1.) tabName must not contain spaces (which is not clear from the help pages).
2.) You had a bracket error (Second tabItem was not included in the brackets of tabItem.
If you correct those two mistakes, the UI is working fine:
ui <- dashboardPage(
dashboardHeader(title = "Enrolment Analytics"),
dashboardSidebar(sidebarMenu(
#can change tab names and icons here.
menuItem("Summary Tables", tabName = "SummaryTables", icon = icon("table")),
menuItem("Visualizations", tabName = "Visualizations", icon = icon("line-chart"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "SummaryTables",
fluidRow(
box(title = "Teaching Load ", status = "primary", solidHeader = TRUE,
selectInput("courseCode1", "Course code: ",
choices = 1:5),
numericInput("Month", "1 = January, 2 = February, ..., 12 = December", value = 6),
numericInput("Year", "2007, 2008, ..., 2017", value = 2007)
),
box(title = "Summary ", status = "primary", solidHeader = TRUE,
plotOutput("tl1"))
)),
## BRACKET ERROR WAS HERE
tabItem(tabName = "Visualizations",
fluidRow(
box(title = "Teaching Load", status = "primary", solidHeader = TRUE,
selectInput("courseCodeOne", "First discipline: ",
choices = 1:10),
selectInput("courseCodeTwo", "Second discipline: ",
choices = 1:10),
selectInput("courseCodeThree", "Third discipline: ",
choices = 1:10)
),
box(title = "Teaching Load Graph", status = "primary", solidHeader = TRUE,
plotOutput("tl2"))
)
)
))
)
server = function(input, output, session){
}
shinyApp(ui, server)
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))
))
})
}
)
I created my shiny dashboard sidebar like this
I linked MenuItem to tabItem, by tabName and in each tabItem I put tabsetPanel
I would like, when I choose group A, to be able to display the different panels that are the subgroups A1, A2, and A3. I would like to do the same for group B and its subgroups. I can't do it, because only the panels in group B are displayed. I would like to keep this dashboardSidebar architecture.
Here are below my scripts
ui <- dashboardPage(
dashboardHeader(title = "DASHBOARD"),
dashboardSidebar(width = 250,
sidebarMenu(
menuItem( "Group A",tabName = "gpA",
selectInput(inputId = "Var1",label="variable 1", choices = c("Total","cat1","cat2"),
selected="Total"),
selectInput(inputId = "Var2",label="variable 2", choices = c("Total","cat1","cat2"),
selected="Total")),
menuItem("Group B",tabName = "gpB")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "gpA",
fluidRow(box(selectInput(inputId = "Hospital1",choices = c(LETTERS),
label = "Choice hospital 1"),
width = 6,height = 70,
solidHeader = TRUE),
box(selectInput(inputId = "Hopital2",choices = rev(c(LETTERS)),
label = "Choice hospital 2"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group A2",
box(leafletOutput("")),box(leafletOutput(""))
),
tabPanel("Sub group A3", box(leafletOutput("")),
box(leafletOutput(""))),
tabPanel("Concurrence", leafletOutput(""))
))
),
tabItem(
tabName = "gpB",
fluidRow(box(selectInput(inputId = "Commune",choices = c(letters),
label = "choice a Zip code"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group B1",
leafletOutput("")
),
tabPanel("Sub group B2",
leafletOutput(""))
))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
As you are using multiple selectInputs (sub items) within the first sidebarmenu item, you need to use menuSubItem (or menuItem) under that to use the tabName. Here tabName gpA1 is what you need to refer to in dashboardBody. You cannot access the tabpanels with gpA when you have sub-items. Try this
ui <- dashboardPage(
dashboardHeader(title = "DASHBOARD"),
dashboardSidebar(width = 250,
sidebarMenu( id="tabs",
menuItem( "Group A", tabName = "gpA",
selectInput(inputId = "Var1",label="variable 1", choices = c("Total","cat1","cat2"),
selected="Total"),
selectInput(inputId = "Var2",label="variable 2", choices = c("Total","cat1","cat2"),
selected="Total"),
menuSubItem("My Group A", tabName="gpA1", ### <---- refer to this tabName in dashboardBody
icon = icon("line-chart"))
),
menuItem("Group B",tabName = "gpB")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "gpA1",
fluidRow(box(selectInput(inputId = "Hospital1",choices = c(LETTERS),
label = "Choice hospital 1"),
width = 6,height = 70,
solidHeader = TRUE),
box(selectInput(inputId = "Hopital2",choices = rev(c(LETTERS)),
label = "Choice hospital 2"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group A2",
box(leafletOutput("")),box(leafletOutput(""))
),
tabPanel("Sub group A3", box(leafletOutput("")),
box(leafletOutput(""))),
tabPanel("Concurrence", leafletOutput(""))
))
),
tabItem(
tabName = "gpB",
fluidRow(box(selectInput(inputId = "Commune",choices = c(letters),
label = "choice a Zip code"),
width = 6,height = 70,
solidHeader = TRUE)),
fluidRow( tabsetPanel(
tabPanel("Sub group B1",
leafletOutput("")
),
tabPanel("Sub group B2",
leafletOutput(""))
))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
I refer to codes from shiny widget gallery to create a fileInput widget on my shinydashboard.
ui.R
fluidPage(
# Copy the line below to make a file upload manager
fileInput("file", label = h3("File input")),
hr(),
fluidRow(column(4, verbatimTextOutput("value")))
)
server.R
function(input, output) {
# You can access the value of the widget with input$file, e.g.
output$value <- renderPrint({
str(input$file)
})
}
I expect my app to show "file upload progress", "upload complete" status and "summary" of the file just like image below.
Below are my codes for shinydashboard:
** for your convenience, refer to "tab Item" = "file".
library(shinydashboard)
library(shiny)
# define user interface
ui <- dashboardPage(
dashboardHeader(title = "B. Times Square"),
dashboardSidebar(
sidebarMenu(
menuItem(text = "Overview", tabName = "overview", icon = icon("balance-scale-right")),
menuItem(text = "Future", tabName = "future", icon = icon("map-signs")),
menuItem(text = "History", tabName = "history", icon = icon("history")),
menuItem(text = "File Upload", tabName = "data", icon = icon("file-upload"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "overview",
fluidRow(
infoBox(title = "Revenue", 1000, icon = icon("hand-holding-usd")),
infoBox(title = "Transaction", 50, icon = icon("bed")),
infoBox(title = "Occupancy %", 40, icon = icon("percentage"))
)
),
tabItem(tabName = "future",
fluidRow(
box(
title = "Revenue [Book]", width = 4,
plotOutput(outputId = "p1-revenue-book")
),
box(
title = "Revenue [Check-In]", width = 4,
plotOutput(outputId = "p2-revenue-checkin")
),
box(
title = "RevPAR", width = 4,
plotOutput(outputId = "p3-revpar")
)
),
fluidRow(
box(
title = "Revenue [Channel]", width = 4,
plotOutput(outputId = "p4-revenue-channel")
),
box(
title = "Occupancy [unit]", width = 4,
plotOutput(outputId = "p5-occupancy")
),
box(
title = "Book vs Cancel [Unit]", width = 4,
plotOutput(outputId = "p6-book-vs-cancel")
)
)
),
tabItem(tabName = "history",
fluidRow(
box(
title = "Revenue [Check-In]", width = 4,
plotOutput(outputId = "p2-revenue-checkin")
),
box(
title = "Revenue [Book]", width = 4,
plotOutput(outputId = "p1-revenue-book")
),
box(
title = "RevPAR", width = 4,
plotOutput(outputId = "p3-revpar")
)
),
fluidRow(
box(
title = "Revenue [Channel]", width = 4,
plotOutput(outputId = "p4-revenue-channel")
),
box(
title = "Occupancy [unit]", width = 4,
plotOutput(outputId = "p5-occupancy")
),
box(
title = "Book vs Cancel [Unit]", width = 4,
plotOutput(outputId = "p6-book-vs-cancel")
)
)
),
tabItem(tabName = ***"data"***,
column(width = 4,
fluidRow(
wellPanel(
fileInput(inputId = "***csv-upload***", label = "File Upload:",
accept = c("csv", ".csv"))
)
)
)
)
)
)
)
# define server
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
I click on "Run App", tried to upload csv file but I don't see any progress bar or file upload complete status after I select a file. The widget basically doesn't work at all.
I am trying to build a simple app using Shinydashboard. One of the tabitems ("Raw Data") does not display anything and neither the page changes when clicked on it. I have cross-checked the syntax and the code is running fine. Don't understand what's wrong.
Ui.R-
header = dashboardHeader(title="COVID-19 Tracker")
sidebar = dashboardSidebar(collapsed = TRUE,
sidebarMenu(menuItem("Dashboard", tabName = "Dashboard",icon = icon("globe")),
menuItem("Raw Data", tabName = "Raw Data", icon = icon("database")),
menuItem("Graphs",tabName = "Graphs", icon = icon("chart-bar"))
))
body = dashboardBody(
tabItems(
tabItem(tabName = "Dashboard",
fluidRow(valueBox(10*3, "Cases", width = 4),
valueBoxOutput("Recovered", width = 4),
valueBoxOutput("Deaths", width = 4)
)
),
tabItem(tabName = "Raw Data", h2("Raw Data has been loaded!")
),
tabItem(tabName = "Graphs",fluidRow(
column(
width=4,
selectizeInput(
"country", label=h5("Country"), choices=NULL, width="100%")
),
column(
width=4,
selectizeInput(
"state", label=h5("State"), choices=NULL, width="100%")
),
column(
width=4,
checkboxGroupInput(
"metrics", label=h5("Selected Metrics"),
choices=c("Confirmed", "Deaths", "Recovered"),
selected=c("Confirmed", "Deaths", "Recovered"),
width="100%")
)
),
fluidRow(
plotlyOutput("dailyMetrics")
),
fluidRow(
plotlyOutput("cumulatedMetrics"))
)
)
)
ui = dashboardPage(header, sidebar, body)
I appreciate all the help!
That's because of the white space in tabName = "Raw Data". Remove it and this works.
I have a simple shiny dashboard that has four tabs in the side menu, and for some reason, when I build the shiny app, clicking on the side menu does not show me a new page, and the content of tab2 just appends itself to tab1.
While searching stackoverflow showed me this question: Shinydashboars tabItems not working properly, the answer doesn't apply to me since I'm not using rmd, and i don't plan to host it to a AWS server.
Here is the code for reference:
ui <- dashboardPage(
dashboardHeader(title = "Study Dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Overall Objectives", tabName = "objectives"),
menuItem("Wellpad Operator", tabName = "wellpad_operator"),
menuItem("Wastewater Expert", tabName = "wastewater_expert"),
menuItem("Freshwater Expert", tabName = "freshwater_expert"),
menuItem("Environmental Impact", tabName = "environ_impact")
)
),
dashboardBody(
#Tab 1 Objective View
tabItems(
tabItem(tabName = "objectives",
h2("Overall Objectives"),
fluidRow(
box(
title = "Overall Objective Comparison", width = 6, solidHeader = TRUE,
plotOutput("objective_plot")
),
box(
title = "Cost Category Breakdown", width = 6, solidHeader = TRUE,
plotOutput("costbreakdown_plot")
),
box(
title = "Decision Variables", width = 12, solidHeader = TRUE,
tableOutput("decision_table"))
))
),
#Tab 2 Wellpad Decision
tabItem(tabName = "wellpad_operator",
h2("Wellpad Operator")
),
#Tab 3 Wastewater Expert
tabItem(tabName = "wastewater_expert",
h2("Wastewater Expert")
),
#Tab 4 Freshwater Expert
tabItem(tabName = "freshwater_expert",
h2("Freshwater Expert")
),
#Tab 5 Environmental Damages
tabItem(tabName = "environ_impact",
h2("Environmental Impact"))
)
)
server <- function(input, output) {
#server side code that generates the plots
}
shinyApp(ui = ui, server = server)
Thanks for all your help!
You need to put all your tabItem inside tabItems. Try this:
dashboardBody(
#Tab 1 Objective View
tabItems(
tabItem(tabName = "objectives",
h2("Overall Objectives"),
fluidRow(
box(
title = "Overall Objective Comparison", width = 6, solidHeader = TRUE,
plotOutput("objective_plot")
),
box(
title = "Cost Category Breakdown", width = 6, solidHeader = TRUE,
plotOutput("costbreakdown_plot")
),
box(
title = "Decision Variables", width = 12, solidHeader = TRUE,
tableOutput("decision_table"))
)),
#Tab 2 Wellpad Decision
tabItem(tabName = "wellpad_operator",
h2("Wellpad Operator")
),
#Tab 3 Wastewater Expert
tabItem(tabName = "wastewater_expert",
h2("Wastewater Expert")
),
#Tab 4 Freshwater Expert
tabItem(tabName = "freshwater_expert",
h2("Freshwater Expert")
),
#Tab 5 Environmental Damages
tabItem(tabName = "environ_impact",
h2("Environmental Impact"))
)
)