I created a Shiny dashboard in line of below codes :
library(shinydashboard)
library(shiny)
sidebar <- dashboardSidebar(
sidebarMenuOutput("menu"),
conditionalPanel("input.tabs == 'ABC'",
fluidRow(
column(11, offset = 1, h5((' Note')))
)
),
conditionalPanel("input.tabs == 'ABC1'",
fluidRow(
column(11, offset = 1, style = "height:20px; color:rgb(30,144,255);", h1((' Update')))
)
))
body <- dashboardBody(
tabItems(
tabItem(tabName = "ABC1",br())
),
tabItems(
tabItem(tabName = "ABC",br(),
fixedRow(column(10, offset = 1, wellPanel()))
)
)
)
ui = dashboardPage(
dashboardHeader(title = "ABC"),
sidebar,
body
)
server = function(input, output){
output$menu <- renderMenu({
sidebarMenu(id="tabs",
menuItem("ABC", tabName="ABC", icon=icon("line-chart"), selected=TRUE),
menuItem("ABC1", tabName="ABC1", icon=icon("line-chart"))
)
})
}
shinyApp(ui = ui, server = server)
With above setup, the width of WellPanel getting changed if I resize my Browser. Therefore, this looks ugly when I see my App in bigger screen (e.g. 2560 x 1080). I want entire size of WellPanel will remain fixed. If Browser size is smaller than WellPanel then, some horizontal/vertical scroll bar will appear. And if bigger then, Wellpanel will stay in the top-middle part of the Browser.
Any idea what setting needs to be changed in my above code to achieve this.
Thanks,
I think this works:
library(shinydashboard)
library(shiny)
sidebar <- dashboardSidebar(
sidebarMenuOutput("menu"),
conditionalPanel("input.tabs == 'ABC'",
fluidRow(
column(11, offset = 1, h5((' Note')))
)
),
conditionalPanel("input.tabs == 'ABC1'",
fluidRow(
column(11, offset = 1, style = "height:20px; color:rgb(30,144,255);", h1((' Update')))
)
))
body <- dashboardBody(
tags$head(tags$style(type = "text/css"
, '#plotUI {min-width: 570px; max-width: 570px;overflow:auto;}'
)
)
,tabItems(
tabItem(tabName = "ABC1",br())
),
tabItems(
tabItem(tabName = "ABC",br(),
fluidRow(column(10, offset = 1
,div(class="thiswell"
, wellPanel(
style= "min-width: 600px;max-width: 600px;overflow:auto",
,uiOutput("plotUI")
)
)
) )
)
)
)
ui = dashboardPage(
dashboardHeader(title = "ABC"),
sidebar,
body
)
server = function(input, output){
output$menu <- renderMenu({
sidebarMenu(id="tabs",
menuItem("ABC", tabName="ABC", icon=icon("line-chart"), selected=TRUE),
menuItem("ABC1", tabName="ABC1", icon=icon("line-chart"))
)
})
output$plotUI<- renderUI({
plotOutput("thePlot")
})
output$thePlot<- renderPlot({
plot(1:10)
})
}
shinyApp(ui = ui, server = server)
Related
I am using boxSidebar for my non-english shiny app, and would really like to replace the 'More' text that appears on hovering over the icon. Can anyone help me with a solution for this?
Alternatively, I was thinking to remove it by using shinyjs::hide(), but the ID seems to change on every hover so I do not know if that's an option here.
minimum example:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
body = dashboardBody(
box(
title = "Hover icon",
sidebar = boxSidebar(
id = "mycardsidebar",
p("Sidebar Content")
)
)
),
sidebar = dashboardSidebar()
),
server = function(input, output, session) {
}
)
We can use {htmltools} to do the work:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(htmltools)
library(magrittr)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
body = dashboardBody(
box(
title = "Hover icon",
sidebar = boxSidebar(
id = "mycardsidebar",
p("Sidebar Content")
)
) %>% {
tagQuery(.)$
find("#mycardsidebar")$
removeAttrs("data-original-title")$
addAttrs(`data-original-title`="whatever")$
allTags()
}
),
sidebar = dashboardSidebar()
),
server = function(input, output, session) {
}
)
change whatever to your text.
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.
I wanted to create fluidPage as shown in the image above.
Here is my code for ui.R:
shinyUI(fluidPage(
fluidRow(
column(6,
selectInput(inputId="StoreName", label=h3("Choose Store"),choices = vStores),
),
column(6,
strong(h3("Latest Orders Status")),
DT::dataTableOutput('getLatestOrdStatus'),
style = "height:500px; overflow-y: scroll;"
)
),
fluidRow(
column(6,
selectInput(inputId="OrderType", label=h3("Choose Order Type"),choices = vOrdTypes)
)
),
fluidRow(
column(5, h4("Daily Orders Count By Order Type"),
dateRangeInput(inputId="daterange", label="Pick a Date Range:", start = Sys.Date()-30,
end = Sys.Date()),
plotOutput("OrdPlotByType")
)
)
)
)
The below code will give you similar layout. Further you can improve by exploring this link from shiny
library(shiny)
library(DT)
library(ggplot2)
data(mtcars)
ui <- fluidPage(
fluidRow(column(12, style = "background-color:#999999;",
fluidRow(column(6,
fluidRow( column(6, selectInput(inputId = "StoreName", label = h3("Select Input 1"),choices = c('a', 'b')))),
fluidRow(column(6, selectInput(inputId = "OrderType", label = h3("Select Input 2"),choices = c('a', 'b')))),
fluidRow(column(12, h4("Plot Output"), plotOutput('plot'))
)) ,
column(6, strong(h3("Table Output")),dataTableOutput('table')
)
)
)
)
)
server <- function(input, output) {
data <- data.frame(
name = c("A","B","C","D","E") ,
value = c(3,12,5,18,45) )
output$table <- renderDataTable(head(mtcars))
output$plot <- renderPlot(
ggplot(data, aes(x = name, y = value)) +
geom_bar(stat = "identity")
)
}
shinyApp(ui, server)
How can we change color theme of DT table in shiny app? By default, it uses dark and light-grey color for alternate rows. I am using formatStyle(target = 'row', backgroundColor = c('yellow', 'red'). But it does not work as it works on columns only
library(shinydashboard)
header <- dashboardHeader(title = 'title')
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
)
)
body <- dashboardBody(
box(
title = 'box', width = NULL, status = 'primary',
DT::dataTableOutput('table2')
)
)
ui<-dashboardPage(header, sidebar, body)
server = function(input, output) {
output$table2 = DT::renderDataTable(
iris, options = list(lengthChange = FALSE)
)
}
shinyApp(ui, server)
This should do, note that i left the header color white:
library(shinydashboard)
library(shiny)
library(DT)
header <- dashboardHeader(title = 'title')
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem('dashboard', tabName = 'dashboard', icon = icon('dashboard'))
)
)
body <- dashboardBody(
tags$style(HTML('table.dataTable tr:nth-child(even) {background-color: pink !important;}')),
tags$style(HTML('table.dataTable tr:nth-child(odd) {background-color: yellow !important;}')),
tags$style(HTML('table.dataTable th {background-color: white !important;}')),
box(
title = 'box', width = NULL, status = 'primary',
DT::dataTableOutput('table2')
)
)
ui<-dashboardPage(header, sidebar, body)
server = function(input, output) {
output$table2 = DT::renderDataTable(
iris, options = list(lengthChange = FALSE)
)
}
shinyApp(ui, server)
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)