Code Monkey home page Code Monkey logo

Comments (4)

wch avatar wch commented on August 22, 2024

That should already be possible.

from shinydashboard.

jchan-scc avatar jchan-scc commented on August 22, 2024

Is this the syntax for instance? It doesnt work for me

sidebarMenu(
    menuItem("A", tabName = "a",  icon = icon("group", lib="font-awesome"))
    ,menuItem("B", tabName = "b", icon = icon("check-circle", lib = "font-awesome"))
    ,menuItem("C", tabName = "c", icon = icon("coffee", lib = "font-awesome"))  
    ,helpText("hello!")
)

from shinydashboard.

wch avatar wch commented on August 22, 2024

You're right, that didn't work right before - the content had to go outside of the sidebarMenu. I've made it more tolerant in aac931c. Here's an example app that shows how to place content in a number of different places.

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(id = "sidebarmenu",
      menuItem("A", tabName = "a",  icon = icon("group", lib="font-awesome")),
      menuItem("B", tabName = "b", icon = icon("check-circle", lib = "font-awesome")),
      sliderInput("b", "Under sidebarMenu", 1, 100, 50),
      menuItem("Sub-items C",
        sliderInput("c1", "Under menuItem 1", 1, 100, 50),
        sliderInput("c2", "Under menuItem 2", 1, 100, 50)
      )
    ),
    sliderInput("x", "Outside of menu", 1, 100, 50)
  ),
  dashboardBody()
)

server <- function(input, output) {}

shinyApp(ui, server)

from shinydashboard.

JAWeber8 avatar JAWeber8 commented on August 22, 2024

Hi
Hope this is the correct spot for this.
I'm working on a ShinyDashboard with input in sidebarMenu / MenuItem. Content comes up perfectly but cannot get it to connect with dashboardBody. Large plot (output$Sum1) detailed below works perfectly when input is within dashboardBody.

Any help would be greatly appreciated.

JW

library(shiny)
library(shinydashboard)
library(shinythemes)
library(shinyWidgets)
library(dplyr)
library(tidyverse)
library(readxl)
library(writexl)
library(formattable)
library(DT)
library(zoo)
library(lubridate)
library(plotly)
library(shinycssloaders)
library(shinydashboardPlus)

ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Load Summary", tabName = "LoadS", icon = icon("dashboard"),
selectInput(inputId = "SQD",
label = "Select Squad",
choice = c("Senior", "Academy")),
selectInput(inputId = "LoadSum",
label = "Load Summary",
choice = c("Distance", "AvgSpeed", "HSR", "Sprints", "COD_Load")))

dashboardBody(tabItems(
tabItem(tabName = "LoadS",
fluidRow(
box(plotlyOutput("Sum1", height = 400) %>% withSpinner(color="#0dc5c1")

                )#box
            )#fluidRow
    ),#tabItem

)#dashboardBody
)#tabItems
)#dashboardPage

server <- function(input, output) {

output$Sum1 <- renderPlotly({
    
    SQ1 <- input$SQD
    VAR <- input$LoadSum
    
    TG3 <- RG3 %>% filter(Squad == SQ1) %>%
        filter(Type == "All Session") %>% 
         filter(Variable == VAR)
    
    TG4 <- TG3 %>% group_by(Date) %>% 
        summarize(Avg_Var = mean(Data),
                  Var_sd = sd(Data)) %>% 
        mutate(Event = "Training") %>% 
        mutate_if(is.numeric, round, digits = 2)
    
    ###########################################################
    #Summarize Game
    GA1 <- RG3 %>% filter(Type == "Game") %>% 
        filter(Squad == SQ1) %>% 
        filter(Variable == VAR)
    
    GA2 <- GA1 %>% group_by(Name, Date) %>% 
        summarize(Sum_Var = sum(Data))
    
    Date <- GA2 %>% pull(Date)
    Variable <- GA2 %>% pull(Sum_Var)
    BI <- bind_cols(Date, Variable) %>% 
        rename(Date = c(1), Variable = c(2))
    
    BI2 <- BI %>% group_by(Date) %>% 
        summarize(Avg_Var = mean(Variable),
                  Var_sd = sd(Variable)) %>% 
        mutate(Event = "Game") %>% 
        mutate_if(is.numeric, round, digits = 2)
    ############################################################
    #Full data set + add TSB Variables
    FD <- bind_rows(BI2, TG4)
    
    GF <- FD %>% filter(Date >= as.Date("2020-12-04") & Date <= as.Date("2020-12-16"))
    
    GFa <- GF %>% mutate(Avg_Var = Avg_Var - Avg_Var) %>% 
        mutate(Var_sd = Var_sd - Var_sd)
    
    FG <- FD %>% filter(Date <= as.Date("2020-12-04") | Date > as.Date("2020-12-16")) 
    
    FD <- bind_rows(GFa, FG)
    
    FD2 <- FD %>% arrange(Date) %>% 
        mutate(A_Load = zoo::rollmean(Avg_Var, k = 7, fill = NA, align = "right"),
               C_Load = zoo::rollmean(Avg_Var, k = 28, fill = NA, align = "right")) %>% 
        mutate(TSB = A_Load / C_Load) %>% 
        mutate(Date = as.Date(Date)) %>% 
        mutate_if(is.numeric, round, digits = 2)
    ############################################################
    
    p <- ggplot(FD2, aes(Date, Avg_Var, label = Event)) + 
        geom_smooth(method = 'loess', alpha = 0.1, show.legend = FALSE, fill = "lightsteelblue", colour = "grey99", span = 0.3) +
        geom_point(size=2.5, shape=21,  colour = "slategrey", fill="slategrey") +
        geom_point(data=subset(FD2, Event == "Game"), color = "red", fill = "red") +
        geom_errorbar(aes(ymin=Avg_Var-Var_sd, ymax=Avg_Var+Var_sd), width=.2, 
                      position=position_dodge(0.05), alpha = 0.4)+
        geom_line(aes(y = A_Load),  color = "green", size = 1.2, alpha =0.5) +
        geom_line(aes(y = C_Load), color = "blue", size = 1.2, alpha =0.3) +
        theme_classic() 
    
    fig <- ggplotly(p)
    
    fig    
})}

shinyApp(ui, server)

from shinydashboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.