dashboardSidebar : size of the page - shiny

Someone can help me to resolve this display problem ?

It depends on what layout you are using. If you are using Column based layout for your boxes, then you can set the box(width=NULL). That should fix the issue. From you code it looks like you are using column based layout. width =25 does not make sense. Since, the overall width of the are is 12. So, set it to width = NULL, it will fix the issue.
If you are using row based layout that is when you mess with the width parameters.

ui <- dashboardPage(
skin = "red",
dashboardHeader(title = "TEXT MINING", disable = F),
dashboardSidebar(
tags$style(
"text/css",
".navbar {background-color:bule;}",
"html,body,#map body {width:120%;height:100%}"
),
br(),
br(),
br(),
br(),
tags$head(tags$style(
".wrapper {overflow: visible !important;}"
)),
selectInput("choix", h2("ALL vs PRIO"), c("ALL", "PRIO")),
helpText("ALL= Tout les clients, PRIO= Clients séléctionés(Prioritaires)"),
selectInput("w", h2("Pondération de la matrice "), c("Tf", "TfIdf")),
br(),
br(),
br(),
br(),
helpText("Cliquer pour téléharger la table"),
downloadButton('downloadData', 'Download'),
br(),
br(),
br(),
br(),
br(),
br(),
br(),
br()
),
dashboardBody(mainPanel(tabsetPanel(
navbarPage(
"",
tabPanel("Données", icon = icon("database"), dataTableOutput('donnees')),
tabPanel(
"Analyses exploratoires",
icon = icon("bar-chart"),
box(
title = "Les pages visitées",
status = "warning",
width = 25,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("pages", height = "650px")
),
box(
title = "Histogramme des notations ",
status = "warning",
width = 25,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("his", height = "650px")
),
box(
title = "score par nombre d'étoile",
status = "warning",
width = 25,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("sc", height = "650px")
) ,
box(
title = "Mots fréquents",
status = "warning",
width = 25,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("mots", height = "650px")
)
),
tabPanel(
"Nuages et assosciations des mots ",
icon = icon("cloud"),
fluidRow(column(12, wellPanel(
sliderInput(
"max",
"Nombre maximal de mots",
min = 100,
max = 300,
value = 200,
step = 10
)
)),
column(
12,
box(
title = "Word Cloud",
status = "warning",
width = 18,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("nuage", height = "450px")
)
)),
fluidRow(column(12, wellPanel(
sliderInput(
"lowf",
"Choisir n tel que Fréquence(mots)>n",
min = 5,
max = 30,
value = 10,
step = 1
)
)),
column(
12,
box(
title = "Graphe des associations",
status = "warning",
width = 18,
solidHeader = TRUE,
collapsible = T,
plotOutput("asso", height = "650px")
)
))
),
tabPanel("Clustering", icon = icon("sitemap"), fluidRow(column(
12,
box(
title = "K-means",
status = "warning",
width = 30,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("cl", height = "650px")
)
),
column(
12,
box(
title = "CAH",
status = "warning",
width = 30,
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("cl2", height = "650px")
)
))),
tabPanel(
"Rapport",
icon = icon("book") ,
tags$iframe(style = "height:800px; width:100%; scrolling=yes",
src =
"rapportTextMining.pdf")
)
)
))))

Related

I can't manage creating a reactive boxplot that takes two different inputs in shiny

I've managed to filter a DataTable with two SelectInput in my code. But, when I try to do the same in my boxplot and histogram it doesn't seem to filter. Is there, by any chance, someone to help me with this? I'm new to shiny.
My code is something like this:
afastamentos <- readr::read_csv("base_afastamentos.csv", locale = locale(encoding = "latin1"))
colnames(afastamentos) <- c(
"Descrição do Cargo", "Nome do Órgão de Origem", "UF", "Cidade da Residência",
"Nível da Escolaridade", "Início do Afastamento", "Ano/Mês Referência",
"Valor do Rendimento Líquido", "Descrição do Afastamento", "Ano Início Afastamento",
"Mês Início Afastamento", "Rendimento Líquido Hora")
ui <- dashboardPage(
dashboardHeader(title = "COBRADI",
titleWidth = 500,
tags$li(class = "dropdown",
tags$a(href = "https://www.ipea.gov.br/portal/index.php?option=com_content&view=article&id=39285&Itemid=343",
icon("globe", lib = "glyphicon"),
"Site COBRADI",
target = "_blank"))
),
dashboardSidebar(
sidebarMenu(
id = "sidebar",
menuItem("Dataset",
tabName = "data",
icon = icon("database")),
menuItem("Visualização",
tabName = "viz",
icon = icon("chart-line")),
menuItem("Informações",
tabName = "info",
icon = icon("info-circle"))
)
),dashboardBody(
tabItems(
tabItem(tabName = "viz",
tabBox(id = "t2", width = 12,
tabPanel(title = "Distribuição Amostral",
icon = icon("fas fa-chart-area"),
value = "trends",
fluidRow(
column(width = 12,
box(title = "Filtros", width = "100%",
column(width = 6,
box(width = "100%",
selectizeInput(inputId = "select_UF",
label = "Estados:",
choices = c("TODOS", unique(afastamentos$UF)),
multiple = T,
selected = "TODOS"))
),
column(width = 6,
box(width = "100%",
selectizeInput(inputId = "descricao_2",
label = "Descrição do Afastamento:",
choices = c("TODOS", unique(afastamentos$`Descrição do Afastamento`)),
multiple = T, options = list(maxItems = 5),
selected = "TODOS"))),
)
)
),
fluidRow(
column(width = 12,
box(title = "BoxPlot - Valor do Rendimento Bruto Mensal",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
width = "100%",
plotlyOutput("boxplot"))
),
column(width = 12,
box(title = "Histograma - Valor do Rendimento Bruto Mensal",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
width = "100%",
plotlyOutput("histplot")))
)
)
)
)
)
)
)
And the server is:
server <- function(input, output, session){
meus_dados <- reactive({
## filtro UF
print(input)
if (! "TODOS" %in% input$select_UF){
a <- a |>
filter(`UF` %in% input$select_UF)
}
#Filtro Descricao
if(! "TODOS" %in% input$descricao_2){
a <- a |>
filter(`Descrição do Afastamento` %in% input$descricao_2)
return(a)
}
})
output$boxplot <- renderPlotly({
boxplot <- meus_dados()|>
plot_ly() |>
add_boxplot(~`Valor do Rendimento Líquido`) |>
layout(xaxis = list(title = "Valor do Rendimento Bruto"))
})
output$histplot <- renderPlotly({
hist <- meus_dados() |>
plot_ly() |>
add_histogram(~`Rendimento Líquido Hora`) |>
layout(xaxis = list(title = "Valor da Hora Técnica"))})
}
And I get the following error: First argument data must be a data frame or shared data.
Data is available here: https://www.dropbox.com/s/kjilkkskggi27vo/base_afastamentos.csv?dl=0
Your reactive object was the problem. This works fine for me using the original names.
ui <- dashboardPage(
dashboardHeader(title = "COBRADI",
titleWidth = 500,
tags$li(class = "dropdown",
tags$a(href = "https://www.ipea.gov.br/portal/index.php?option=com_content&view=article&id=39285&Itemid=343",
icon("globe", lib = "glyphicon"),
"Site COBRADI",
target = "_blank"))
),
dashboardSidebar(
sidebarMenu(
id = "sidebar",
menuItem("Dataset",
tabName = "data",
icon = icon("database")),
menuItem("Visualização",
tabName = "viz",
icon = icon("chart-line")),
menuItem("Informações",
tabName = "info",
icon = icon("info-circle"))
)
),dashboardBody(
tabItems(
tabItem(tabName = "viz",
tabBox(id = "t2", width = 12,
tabPanel(title = "Distribuição Amostral",
icon = icon("fas fa-chart-area"),
value = "trends",
fluidRow(
column(width = 12,
box(title = "Filtros", width = "100%",
column(width = 6,
box(width = "100%",
selectizeInput(inputId = "select_UF",
label = "Estados:",
choices = c("TODOS", unique(afastamentos$UF_da_UPAG_de_vinculacao)),
multiple = T,
selected = "TODOS"))
),
column(width = 6,
box(width = "100%",
selectizeInput(inputId = "descricao_2",
label = "Descrição do Afastamento:",
choices = c("TODOS", unique(afastamentos$Descricao_do_afastamento)),
multiple = T, options = list(maxItems = 5),
selected = "TODOS"))),
)
)
),
fluidRow(
column(width = 12,
box(title = "BoxPlot - Valor do Rendimento Bruto Mensal",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
width = "100%",
plotlyOutput("boxplot"))
),
column(width = 12,
box(title = "Histograma - Valor do Rendimento Bruto Mensal",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
width = "100%",
plotlyOutput("histplot")))
)
)
)
)
)
)
)
server <- function(input, output, session){
meus_dados <- reactive({
## filtro UF
print(input)
a <- afastamentos
if (! "TODOS" %in% input$select_UF){
a <- a |>
filter(UF_da_UPAG_de_vinculacao %in% input$select_UF)
}
#Filtro Descricao
if(! "TODOS" %in% input$descricao_2){
a <- a |>
filter(Descricao_do_afastamento %in% input$descricao_2)
}
return(a)
})
output$boxplot <- renderPlotly({
boxplot <- meus_dados()|>
plot_ly() |>
add_boxplot(~Valor_rendimento_liquido) |>
layout(xaxis = list(title = "Valor do Rendimento Bruto"))
})
output$histplot <- renderPlotly({
hist <- meus_dados() |>
plot_ly() |>
add_histogram(~Rendimento_Liquido_Hora) |>
layout(xaxis = list(title = "Valor da Hora Técnica"))})
}
shinyApp(ui = ui, server = server)

Tabs of the menuItem, in Shinydashboard, not working when put items inside

Lets take the example of the reference: https://rstudio.github.io/shinydashboard/structure.html#sidebar-menu-items-and-tabs. When put more items in the menuItem(), your associate tab don't works anymore. I tried in this simple modification in example below and just shown the widgets' tab:
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Dashboard",
tabName = "dashboard",
icon = icon("dashboard"),
selected = TRUE,
startExpanded = TRUE,
numericInput("num1",
"Put the First Number",
value = 1,
min = 0),
numericInput("num2",
"Put the Second Number",
value = 1,
min = 0)
),
menuItem("Widgets",
icon = icon("th"),
tabName = "widgets")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "dashboard",
h2("Dashboard tab content"),
fluidRow(
valueBoxOutput("box1", width = 6),
valueBoxOutput("box2", width = 6)
)
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
# Put them together into a dashboardPage
ui <- dashboardPage(
skin = "green",
dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output){
output$box1 <- renderValueBox({
valueBox(input$num1,
"First Number",
color = "aqua",
icon = icon("chart-line"))
})
output$box2 <- renderValueBox({
valueBox(input$num2,
"Second Number",
color = "aqua",
icon = icon("chart-line"))
})
}
shinyApp(ui, server)
That is because childfull menuItem behaves differently as noted here. Therefore, you need to define a menuItem or a menSubItem within that dashboard page so that your desired content can be displayed.
Try this
sidebarMenu(id = "tabs",
menuItem("Dashboard",
tabName = "dashboard",
icon = icon("tachometer-alt"),
selected = TRUE,
startExpanded = TRUE,
#icon = icon(fontawesome:::fa_tbl[[1]][505]),
menuItem("Sub-item 1", tabName = "subitem1"),
### menuSubItem("Sub-item 1", tabName = "subitem1"), ## it can be menuSubItem instead of menuItem
numericInput("num1",
"Put the First Number",
value = 1,
min = 0),
numericInput("num2",
"Put the Second Number",
value = 2,
min = 0)
),
menuItem("Widgets",
icon = icon("th"),
tabName = "widgets")
)
)
body <- shinydashboard::dashboardBody(
tabItems(
tabItem(tabName = "subitem1",
h2("Sub item1 tab content in Dashboard"),
fluidRow(
valueBoxOutput("box1", width = 6),
valueBoxOutput("box2", width = 6)
)
),
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
# Put them together into a dashboardPage
ui <- shinydashboard::dashboardPage(
skin = "green",
shinydashboard::dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output, session){
output$box1 <- renderValueBox({
valueBox(input$num1,
"First Number",
color = "aqua",
icon = icon("chart-line"))
})
output$box2 <- renderValueBox({
valueBox(input$num2,
"Second Number",
color = "aqua",
icon = icon("chart-line"))
})
observe({print(input$tabs)})
}
shinyApp(ui, server)

Not showing charts in menusubItems in shinydashboard (with highcharter)

I've been trying for hours on end to get this working however it does not work. I simply wish to render the charts in this dashboard for the different tabs. I have tried enclosing it with box(), using renderHighchart2 and highchartOutput2. The chart renders outside shiny just fine, what is wrong?
Edit: The charts I am referring to are the highcharts, not the valueboxes! Furthermore, the app does show the correct titles for each graph and fluidRow however fails to plot the highcharts
This is the code:
library(shiny)
library(shinydashboard)
library(highcharter)
library(tidyverse)
ui <- dashboardPage(
skin = "purple",
dashboardHeader(title = h4(HTML("Generic company name<br/>Something to analyze")),
titleWidth = 275),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard",icon = icon("dashboard"),
menuSubItem('Samenvatting', tabName = "samenvatting", icon = icon('atlas')),
menuSubItem('Statusverloop', tabName = "statusverloop", icon = icon('battery-three-quarters')),
menuSubItem('Tijdsverloop', tabName = "tijdsverloop", icon = icon("hourglass-end")),
menuSubItem('Affiliates', tabName = "affiliates", icon = icon("handshake")),
menuSubItem('Klanten informatie', tabName = "klanteninformatie", icon = icon("address-card"))
),
menuItem("Kijkglas",tabname = "kijkglas",icon = icon("search"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = 'samenvatting',
#contents
fluidRow(
valueBoxOutput("YTDnieuweA"),
valueBoxOutput("YTDomvangA")
),
fluidRow(
valueBoxOutput("YTDnieuweP") ,
valueBoxOutput("YTDomvangP")
),
fluidRow(
column( width = 6,h4("Wekelijkse statistieken", align = 'center'), highchartOutput('a') ),
column( width = 6,h4("Wekelijkse totale statistieken", align = 'center'), highchartOutput('b'))
)
),
tabItem(tabName = "statusverloop"
#Empty TODO:
),
tabItem(tabName = "tijdsverloop"
#EMPTY: TODO
),
tabItem(tabName = "affiliates",
fluidRow(
column( width = 6,h4("Affiliates over aanmeldingen", align = 'center'), highchartOutput('a') ),
column( width = 6,h4("Affiliates over passen", align = 'center'), highchartOutput('b'))
)
),
tabItem(tabName = "klanteninformatie",
fluidRow(
column( width = 4,h4("Wekelijkse statistieken", align = 'center'), highchartOutput('a') ),
column( width = 4,h4("Wekelijkse totale statistieken", align = 'center'), highchartOutput('b')),
column( width = 4,h4("Wekelijkse totale statistieken", align = 'center'), highchartOutput('a'))
)
)
)
)
)
server <- function(input, output) {
output$a <- renderHighchart2({
hc <- highcharts_demo() %>%
hc_rm_series("Berlin") %>%
hc_chart(type = 'line')
theme <- sandsignika = hc_theme_sandsignika()
hc <- hc %>% hc_add_theme(theme)
}
hc
})
output$b <- renderHighchart2({
hc <- highcharts_demo() %>%
hc_rm_series("Berlin") %>%
hc_chart(type = 'line')
theme <- hc_theme_economist()
hc <- hc %>% hc_add_theme(theme)
}
hc
})
}
shinyApp(ui,server)
In shiny, you can't refer to any output more than once in the UI.
Try storing the chart in an object (could use either a reactiveValues or reactive() to store it), then assigning that object into separate outputs.

how to alter padding in shiny navbar

I'm trying to eliminate the space between this table and the left side of browser window, but when I do, it messes up the spacing of the nav bar links and title.
How can I remove padding/margin on the excelR table, without altering the padding/margin of the navbar/ui/li elements?
library(shiny)
library(excelR)
shinyApp(
ui = navbarPage("title", selected = "main",
position = "fixed-top",
tags$style(type="text/css", "body {padding-top: 70px;}"),
tags$head(
tags$style(
"body {overflow-y: hidden;}"
)
),
tags$head(
tags$style(type = "text/css", ".container-fluid {padding-left:0px;
padding-right:0px; margin-right:0px; margin-left:0px;}")
),
tabPanel("main", id = "main",
fluidPage(
excelOutput("table", width = "100%", height = "1000px")
#htmlOutput("table", width = "100%", height = "500px")
)
)
),
server = function(input, output, session) {
output$table <-renderExcel(
excelTable(
data = iris,
autoColTypes = FALSE,
autoFill = TRUE,
fullscreen = FALSE,
lazyLoading = TRUE,
search = TRUE,
tableHeight = "800px",
pagination <- NULL
)
)
}
)
You can simply add this additional css to your code:
tags$style(type = "text/css", ".navbar{padding-left:15px;
padding-right:15px ; margin-right:auto; margin-left:auto;}")
),
Hope this helps!

sliderInput to appear in side-bar only when a Tab is selected

I am creating a Shinyapp in line of below template :
library(shinydashboard)
sidebar <- dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Tab1", tabName="Tab1", selected=TRUE),
menuItem("Tab2", tabName = "Tab2")
),
conditionalPanel("input.tabs=='Tab1'",
fluidRow()
),
conditionalPanel("input.tabs=='Tab2'",
fluidRow()
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "Tab1",
fluidRow( sliderInput("aa", "aa", value = 0.9, min = 0, max = 2, step=0.1))
),
tabItem(tabName = "Tab2",
fluidRow(navbarPage(id = 'ab', title = "",
tabPanel(title = "aa1", value = 'aa1', fluidRow()),
tabPanel(title = "aa2", value = 'aa2', fluidRow())))
)))
ui = dashboardPage(
dashboardHeader(title = "My tab"),
sidebar,
body
)
server = function(input, output) {}
shinyApp(ui = ui, server = server)
Now what I want basically, a sliderInput should appear in the Side panel only when TabPanel = 'aa2' from tabItem = 'Tab2'. Therefore user should not see that sliderInput if TabPanel = 'aa1' is selected.
So far I have tried something like below :
sidebar <- dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Tab1", tabName="Tab1", selected=TRUE),
menuItem("Tab2", tabName = "Tab2")
),
conditionalPanel("input.tabs=='Tab1'",
fluidRow()
),
conditionalPanel("input.tabs=='Tab2'",
fluidRow(sliderInput("aa5", "aa", value = 0.9, min = 0, max = 2, step=0.1))
)
)
However with this the sliderInput is visible for both tabPanel = "aa1" & tabPanel = "aa2", which I do not want.
Any suggestion, how can I make sliderInput is visible only for tabPanel = "aa2".
Thanks for your pointer.
#SBista thanks for pointer. Below is updated code. Thanks,
library(shinydashboard)
library(shinyjs)
sidebar <- dashboardSidebar(
sidebarMenu(id="tabs",
menuItem("Tab1", tabName="Tab1", selected=TRUE),
menuItem("Tab2", tabName = "Tab2")
),
conditionalPanel("input.tabs=='Tab1'",
fluidRow()
),
conditionalPanel("input.tabs=='Tab2'",
fluidRow(useShinyjs(),
column(12, sliderInput("aa4", "aa", value = 0.9, min = 0, max = 2, step=0.1)))
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "Tab1",
fluidRow( sliderInput("aa", "aa", value = 0.9, min = 0, max = 2, step=0.1))
),
tabItem(tabName = "Tab2",
fluidRow(navbarPage(id = 'ab', title = "",
tabPanel(title = "aa1", value = 'aa1', fluidRow()),
tabPanel(title = "aa2", value = 'aa2', fluidRow())))
)))
ui = dashboardPage(
dashboardHeader(title = "My tab"),
sidebar,
body
)
server = function(input, output) {
observe(toggle(id = "aa4", condition = ifelse(input$ab == 'aa2', TRUE, FALSE)))
}
shinyApp(ui = ui, server = server)