title in tab of browser empty in shiny dashboard page - html

Though there is the posibility to add a title in a shiny dashboard app, which appears correctly in the app page,
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "my title"),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)
It does not appear as the name of tab of the browser. As name of tab in browser only appears the URL (like 127...).

You can set the browser page title like this
ui <- dashboardPage(title="Browser title",
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
...

Related

Why does R Shiny not recognize my line break command?

I have a simple app where I want to have a text pop up, but because the text is long, I want to add line breaks. For some reason, R isn't recognizing my line breaks, even though I've added , like I read in this example.
Any help would be greatly appreciated!
library(shiny)
long_text <- paste0(htmltools::HTML("I have a lot of text. <br><br>And I want it on different lines.<br><br> This should work, but R is being....<br><br>difficult."))
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
br(),
actionButton(inputId = "text_info",
label = "My R Sob Story", style = "color: #FFFFFF; background-color: #CA001B; border_color: #CA001B")
),
mainPanel(
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
observeEvent(input$text_info, {
showModal(modalDialog(long_text, title = strong("Why R you doing this to me?")))
})
}
# Run the application
shinyApp(ui = ui, server = server)
Here's what it looks like now:
If you paste after changing the text to HTML, it will be character again.
library(shiny)
long_text <- htmltools::HTML("I have a lot of text. <br><br>And I want it on different lines.<br><br> This should work, but R is being....<br><br>difficult.")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
br(),
actionButton(inputId = "text_info",
label = "My R Sob Story", style = "color: #FFFFFF; background-color: #CA001B; border_color: #CA001B")
),
mainPanel(
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
observeEvent(input$text_info, {
showModal(modalDialog(long_text, title = strong("Why R you doing this to me?")))
})
}
# Run the application
shinyApp(ui = ui, server = server)

Add Uicons to Shiny from local file

Looking to add uicons to my Shiny app. I have downloaded the fonts after making an account, and moved the CSS and webfonts to the root directory of my .R file.(per instructions) Now I want to add one of the icons in my infobox in Shiny, I have a very simple example
I think I could use some sort of shiny::tags but not sure which one, or how. I used This Stackoverflow answer to help guide me,
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$i("#import url(/css/uicons-regular-rounded.css);"),
icon("fi fi-rr-camera")
))
server <- function(input, output) { }
shinyApp(ui, server)
Which gives me this
Any help would be appreciated. Thank you.
You need to put all folders including svg folder into www folder in root of your shiny app. Then you can import the icon with tags$img(src='svg/fi-rr-camera.svg')
To use it in info box, simply wrap it with tags$i.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$img(src='svg/fi-rr-camera.svg', height='40', width='40')
infoBox("info","info",icon = tags$i(tags$img(src='svg/fi-rr-camera.svg', height='40', width='40')))
))
server <- function(input, output) { }
shinyApp(ui, server)
As #phago29 mentioned, uicons-regular-rounded.css need to be in a subdirectory inside the project directory (or simply the directory using setwd()).
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(includeCSS('www/uicons-regular-rounded.css'),
tags$i(class = "fi fi-rr-camera")))
server <- function(input, output) { }
shinyApp(ui, server)
reproducible example:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(includeCSS('https://fonts.googleapis.com/icon?family=Material+Icons'),
tags$i(class = "material-icons", "accessibility", style = "font-size: 6em;")))
server <- function(input, output) { }
shinyApp(ui, server)

How do I include html / css in my shiny app

below is the shiny app, if I need to add some css into it (attached below), where can i add it so that it renders in r shiny app
css
<style>
.bs-example{
margin: 60px;
}
</style>
ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Stateful"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
tabsetPanel(
id="inTabset",
tabPanel("Tab 1",actionButton("switch_tab", "Go to the third tab")),
tabPanel("Tab 2", "there!"),
tabPanel("Tab 3", "there!"))
)
)
))
server.R
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
})
You can add your CSS file in the ui section, like below:
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "style.css")
)
Keep in mind your CSS file should be in the www directory in your shiny app.

R shiny select part of HTML file by id

I have an application that displays data on indicators. Each indicator (30+) has a definition. We have this definition of all indicators in a single html file (easier to maintain than 30 different ones).
In my ShinyApp, I want to show only the section relevant to the indicator selected, not the full document.
I was wondering how this could be done....
Here is an example that is only showing the full 'document' instead of the part which is selected in the sidebar:
documentation <- structure("<div> <div id=\"part1\"> <h1>Part 1</h1> <p>This is part 1 out of 2</p> <p> </p> </div> <div id=\"part2\"> <p> </p> <h1>Part 2</h1> <p>This is part 2 out of 2.</p> </div> </div>", html = TRUE, class = c("html", "character"))
documentation
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput(inputId = "part",label = "Select the part you want to see", choices = c("part1", "part2"))
),
dashboardBody(
uiOutput("section")
)
)
server <- function(input, output) {
output$section <- renderUI({
HTML(documentation) # This needs subsetting based on input$part
})
}
shinyApp(ui, server)
I came up with a quick and dirty solution, by manipulating the HTML as a string.
I wonder if there are more elegant methods though...
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput(inputId = "part",label = "Select the part you want to see", choices = c("part1", "part2"))
),
dashboardBody(
uiOutput("section")
)
)
server <- function(input, output) {
output$section <- renderUI({
# HTML(documentation)
t1 <- strsplit(documentation, "<div")[[1]][grepl(input$part, strsplit(documentation, "<div")[[1]])]
t2 <- paste0("<div", t1)
t2 <- gsub("</div> </div>", "</div>", t2)
HTML(t2)
})
}
shinyApp(ui, server)

Positioning the text within Action Button in R shiny

I want to fit Resource Activity text within the given button such that Activity comes below the Resource in the button. Currently the complete word gets hidden because of less space of the button and I do not want to increase the space. Please help.
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
actionButton("buttonresinvthree", "Resource Activity",style="color:
#000000; width:8%; ")
)
)
server <- function(input, output) { }
shinyApp(ui, server)
The following works for me:
## app.R ##
library(shiny)
library(shinydashboard)
library(tableHTML)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$head(tags$style(make_css(list('.btn', 'white-space', 'pre-wrap')))),
actionButton("buttonresinvthree", HTML("Resource\nActivity"),
style="color: #000000; width:8%; ")
)
)
server <- function(input, output) { }
shinyApp(ui, server)
I added tags$head... to add CSS to the button (class btn) and used \n for the break line between Resource\nActivity.
The result looks like this:
Set white-space to normal:
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
actionButton("buttonresinvthree", "Resource Activity",style="color:
#000000; width:8%;white-space:normal;font-size:.8vw;")
)
)
server <- function(input, output) { }
shinyApp(ui, server)