Similar to the dropdownMenu and messageItem functions which are available in shinydashboard I would like to show message items on the right hand side of the navbar in a navbarPage based app. Example of the related functions here: https://rstudio.github.io/shinydashboard/structure.html
I have tried inserting the same funcitons into a navbarPage app but it is not working as expected- not right aligned.
As a very basic reproducible example, this is the structure of my app with my attempt at including the message item:
library(shiny)
library(shinydashboard)
ui <- shinyUI(
navbarPage("Navbar!",
tabPanel("Plot",
sidebarLayout(
sidebarPanel(),
mainPanel()
)
),
tabPanel(
dropdownMenu(type = "messages",
messageItem(
from = "Sales Dept",
message = "Sales are steady this month."
)
)
)
)
)
server = function(input, output) { }
shinyApp(ui = ui, server = server)
I'm not the best at css, but this is a start to getting the result you're looking for. Change the UI to:
ui <- shinyUI(
fluidPage(
tags$head(
tags$style(HTML("
.navbar-nav .messages-menu a {padding-top: 0px; padding-bottom:0px}
.navbar-nav {width: 90%}
.navbar-nav .messages-menu {float: right; padding-top: 25px;}
"))
),
navbarPage("Navbar!",
tabPanel("Plot",
sidebarLayout(
sidebarPanel(),
mainPanel()
)
),
tabPanel(
dropdownMenu(type = "messages",
messageItem(
from = "Sales Dept",
message = "Sales are steady this month."
)
)
)
)
)
)
The width sets the class navbar-nav to 90% of the width of the screen since it is the space that contains both tab panels but not the label "Navbar!", and the second line takes the class messages-menu within navbar-nav and shifts it to the right of the space filled by navbar-nav (hence why we had to extend the width to include all of the header not occupied by the label; this percentage would likely have to change depending on the text input that is in place of "Navbar!").
Related
I have a Shiny app built with shinydashboard and I've just discovered shinydashboardPlus. One nice option is to have the sidebarMenu "minified", or when minimized it doesn't go away completely, but just displays the icons for each menuItem. However, with shinydashboardPlus, when minified, the title gets chopped off. With shinydashboard, the title stays intact, but the sidebar goes away completely.
Example code:
library(shiny)
library(shinydashboard)
#library(shinydashboardPlus)
# Basic dashboard page template
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "Example"),
dashboardSidebar(#minified = TRUE,
sidebarMenu(
menuItem('Menu1', tabName = 'Menu1',
icon = icon('folder-open')),
menuItem('Menu2', tabName = 'Menu2',
icon = icon('code-branch'))
)
),
dashboardBody()
),
server = function(input, output) { }
)
Leaving the comment marks in place and running it uses shinydashboard, and gives this initially:
And when the hamburger is clicked to minimize the sidebar, the whole sidebar disappears:
If the comment marks are removed so that it runs using shinydashboardPlus, minimizing it gives this, where I have the icons in the sidebar, but the title is chopped:
Is there a way to get the shinydashboardPlus minification that shows just the icons, but doesn't chop off the title?
Here you go
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
# Basic dashboard page template
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "Example"),
dashboardSidebar(#minified = TRUE,
sidebarMenu(
menuItem('Menu1', tabName = 'Menu1',
icon = icon('folder-open')),
menuItem('Menu2', tabName = 'Menu2',
icon = icon('code-branch'))
)
),
dashboardBody(
tags$style(
'
#media (min-width: 768px){
.sidebar-mini.sidebar-collapse .main-header .logo {
width: 230px;
}
.sidebar-mini.sidebar-collapse .main-header .navbar {
margin-left: 230px;
}
}
'
)
)
),
server = function(input, output) { }
)
change the width and margin-left numbers if you have extreme long titles.
I'm new to Shiny and can't figure out how to "unbold" labels (feed rate and operation in the screenshot attached). Here's my code for the UI part:
ui <- fluidPage(titlePanel(""),
sidebarLayout(
sidebarPanel(
# adding the new div tag to the sidebar
tags$div(class="header", checked=NA,
tags$h4(strong("Duty"))),
selectInput('id1', 'Feed rate (m^3/h)', c("All", main$metric[1:3])),
selectInput('id2', 'Operation', c("All", main$metric[4:5])),
mainPanel(DT::dataTableOutput("table"))
))
And here's the screenshot:
You can do this by adding your own style sheet to your Shiny app. First we give the sidebar panel a class sidebar so we can refer to it. Then we can add the following to a file www/style.css:
.sidebar label {
font-weight: 400;
}
Finally we set the theme parameter of your fluidPage to "style.css".
ui <- fluidPage(theme="style.css", titlePanel(""),
# content here
))
The result should look like this:
This is another option (you don't have to create a file)
library(shiny)
remove_bold <-"
#expr-container label {
font-weight: 400;
}
"
ui <- fluidPage(
titlePanel("My app"),
sidebarLayout(
sidebarPanel(
tags$style(remove_bold), ####### NEW CODE
tags$div(id = "expr-container", ####### NEW CODE
textInput(inputId = "data2", "Data1", value = "data"))
),
mainPanel(
)
)
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
Inspired in this post: How to change the pickerinput label to fine instead of bold
My goal is to change the color of an actionButton in Shine sidebar. In my dashboard content is organized using navbarPage.
I found different solutions, for example:
Using the style argument in actionButton: See here
Using tags directly: See here
These both work great, but as soon as I add a navbar to the dashboard they stop working. The only thing changing color seems to be the border of the button instead of the whole background.
Below a reproducible example.
This works
library(shiny)
shinyApp(
ui = fluidPage(
titlePanel("Styling Action Button"),
sidebarLayout(
sidebarPanel(
h4("Default CSS styling"),
# default styling
actionButton('downloadData1', label= 'Download 1'),
tags$hr(),
actionButton("download1", label="Download with style", class = "butt1"),
# style font family as well in addition to background and font color
tags$head(tags$style(".butt1{background-color:orange;} .butt1{color: black;} .butt1{font-family: Courier New}"))
),
mainPanel()
)
),
server = function(input, output){}
)
This doesn't work
library(shiny)
shinyApp(
ui = fluidPage(
navbarPage("Test multi page",
tabPanel("test",
titlePanel("Styling Action Button"),
sidebarLayout(
sidebarPanel(
h4("Default CSS styling"),
# default styling
actionButton('downloadData1', label= 'Download 1'),
tags$hr(),
actionButton("download1", label="Download with style", class = "butt1"),
# style font family as well in addition to background and font color
tags$head(tags$style(".butt1{background-color:orange;} .butt1{color: black;} .butt1{font-family: Courier New}"))
),
mainPanel()
)
))),
server = function(input, output){}
)
This doesn't work either
library(shiny)
shinyApp(
ui = fluidPage(
navbarPage("Test multi page", theme = shinytheme("cerulean"),
tabPanel("test",
titlePanel("Styling Download Button"),
sidebarLayout(
sidebarPanel(
h4("Default CSS styling"),
# default styling
actionButton('downloadData1', label= 'Download 1'),
actionButton("download1", label="Download with style",
style="color: #fff; background-color: #337ab7")
),
mainPanel()
)
))),
server = function(input, output){})
Referring to your third example, the following works if you don't use shinythemes:
actionButton("download1", "Download with style", style = "color: white; background-color:#4682b4")
You can change color according to your choice. style will change button text color and background-color will change button color using HTML HEX code. You can get any HEX code here: http://htmlcolorcodes.com/
I want to control the appearance of a modalDialog depending on the input of a selectInput, what is the best way to do that? I've tried the following code, but conditionalpanel doesn't work within modalDialog. (showing part of the code)
ui<-fluidPage(
selectInput("v1",c("Active_ingredient","Brand_Name"),
actionButton("tabBut", "Select Drug and Event...", style='primary')
)
server<-function(input, output, session) {
dataModal<-function(failed=FALSE){
modalDialog(
conditionalPanel(
condition="input.v1==Active_ingredient",
selectizeInput_p("t1", "Active Ingredient",
choices=c("start typing to search..."="",ing_choices),
HTML( tt('drugname1') ), tt('drugname2'),
placement='bottom')
),
conditionalPanel(
condition="input.v1==Brand_Name",
selectizeInput_p("t1_1", "Name of Drug",
choices=c("start typing to search..."="",drug_choices),
HTML( tt('drugname1') ), tt('drugname2'),
placement='bottom')
),
selectizeInput_p("t2", "Adverse Events",choices= c("Start typing to search"=""),
HTML( tt('eventname1') ), tt('eventname2'),
placement='left'),
numericInput_p('maxcp', "Maximum Number of Change Points", 3, 1, step=1,
HTML( tt('cplimit1') ), tt('cplimit2'),
placement='left'),
footer = tagList(
modalButton("Cancel"),
actionButton("update", "OK")
)
)
}
observeEvent(input$tabBut, {
showModal(dataModal())
})
}
You might try moving the modal dialog to ui.R, using bsModal.See here for an example:
Create a popup dialog box interactive
Hope this helps! Florian
I am using R-3.2.0 hosted on Red Hat Linux version 6.5 with shiny package (version 0.12.0). I am trying to utilize shinydashboard functionality to design a few reports. The RStudio version is 0.98.1103
I have successfully setup ui.R and server.R
ui.R - :
ibrary(shinydashboard)
library(htmlwidgets)
library(rpivotTable)
library(leaflet)
dashboardPage(
dashboardHeader(title="Reports",
dropdownMenu(type = "task",
messageItem(
from = "Download",
message = "test",
icon = icon("gear")
),
messageItem(
"Download",
message = "TEST",
icon = icon("life-ring"),
href= "http://www.google.com"
)
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Srts", tabName = "ServiceItems", icon = icon("dashboard"))
)
),
dashboardBody(
tags$head(tags$style(
type = 'text/css',
'#test{ overflow-x: scroll; }')),
rpivotTableOutput('PivotTable')
)
)
server.R -:
library(shiny)
library(ggplot2)
library(wordcloud)
library(devtools)
library(htmlwidgets)
library(rpivotTable)
library(leaflet)
shinyServer(function(input, output) {
PivotTable <- read.csv("Book2.csv",head=TRUE,sep= ',')
output$PivotTable <- rpivotTable::renderRpivotTable({
rpivotTable(PivotTable, rows="Ar", col="DTM", aggregatorName="Count",
vals="Ar", rendererName="Table")})
tableFirst<-as.data.frame(sort(table(PivotTable$Area),decreasing=TRUE))
})
The following code to enable scrolling in the dashboard body was taken from https://github.com/smartinsightsfromdata/rpivotTable/issues/19 :-
tags$head(tags$style(
type = 'text/css',
'#test{ overflow-x: scroll; }')),
rpivotTableOutput('PivotTable')
The issue I face is that the code added to help scrolling does not work. I have stripped my code of all tabs , layouts etc but I am still enable to get scrolling to work.
I have observed that if I remove the dashboardPage command, scrolling does work but the display is very awkward and not really presentable.
However, when I combine the codes as follows (in RStudio) and run the scrolling works just fine.
library(shiny)
library(shinydashboard)
library(rpivotTable)
library(ggplot2)
PivotTable <- read.csv("Book2.csv",head=TRUE,sep= ',')
header <- dashboardHeader(title="Reports",
dropdownMenu(type = "task",
messageItem(
from = "Download",
message = "test",
icon = icon("gear")
),
messageItem(
"Download",
message = "TEST",
icon = icon("life-ring"),
href= "http://www.google.com"
)
)
)
sidebar <- dashboardSidebar()
body <- dashboardBody(
tags$head(tags$style(HTML('
.skin-blue.main-header .logo {
background-color: #3c8dbc;
}
.skin-blue .main-header .logo:hover {
background-color: #3c8dbc;
}
'))
),
tags$head(tags$style(type = 'text/css',
'#test{ overflow-x: scroll; }')),
rpivotTableOutput("test")
)
shinyApp(
ui = dashboardPage(header, sidebar, body),
server = function(input, output) {
output$test <- rpivotTable::renderRpivotTable({
rpivotTable(PivotTable, rows="Ar", col="DTM", aggregatorName="Count",vals="Ar", rendererName="Table")})
})
However, I cannot provide this as a final solution because the business users that need this are not adept at copying and pasting code on RStudio (If there is a possible way that I can use the combined code just like the usual one I can consider that as well).
Can someone please help me understand the issue with my original code that prevents scrolling.
Thanks a lot !
The problem is your CSS selector otherwise everything looks OK. Your setting the scroll-property on a element with ID test but I can't find a element with this ID in your example. Try something like this:
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
tags$head(
tags$style(
HTML("
#myScrollBox{
overflow-y: scroll;
overflow-x: hidden;
height:120px;
}
")
)
),
# Boxes need to be put in a row (or column)
fluidRow(
div(id="myScrollBox",
plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)
You need to change the CSS selector to the element you want to put the scroll on, in the example this is "myScrollBox".
The only thing which you should be taking in to consideration is to pass the exact same id before CSS code, so in this code replace #test to #PivotTable and bingo... your code should work...
tags$head(tags$style(
type = 'text/css',
'#test{ overflow-x: scroll; }')),
rpivotTableOutput('PivotTable')