Add Black Border to SidebarPanel and MainPanel - R Shiny - html

How would I add a black boarder to the main panel and side bar panel for the MRE? I would like the panels to stand out slightly more. I have adjusted background color on my app but think adding a black boarder will make each panel stand out better.
UI
library(shiny)
library(shinyalert)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
DT::dataTableOutput("cap_table"),
)
)
))
Server
library(shiny)
library(shinyalert)
data <- data.frame(x=rnorm(10),y=rnorm(10))
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# render data selection
output$cap_table <- DT::renderDataTable(data)
})

You may consider adding custom css to your app. I right click the app when it's running to "inspect" the css class that I would like to change.
Here is an example using in-line code.
Here is a link to consider other approaches such as sourcing a css file. https://shiny.rstudio.com/articles/css.html
library(shiny)
library(DT)
# Define UI for application that draws a histogram
ui <- shinyUI(
fluidPage(
tags$head(
# Note the wrapping of the string in HTML()
tags$style(HTML(".well {
border: 1px solid #000000;
}")),
tags$style(HTML(".col-sm-8 {
border: 1px solid #000000;
}"))
),
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
),
# Show a plot of the generated distribution
mainPanel(
DT::dataTableOutput("cap_table"),
)
)
))
data <- data.frame(x=rnorm(10),y=rnorm(10))
# Define server logic required to draw a histogram
server <- shinyServer(function(input, output) {
# render data selection
output$cap_table <- DT::renderDataTable(data)
})
shinyApp(ui = ui, server = server)

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)

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.

Printing all factor levels as a list in a shiny dashboard

I would like to print all levels of a factor in a shiny dashboard. I know I could easily do that by:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Testing shiny App"),
# Show a plot of the generated distribution
mainPanel(
htmlOutput("my_levels_list")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$my_levels_list <- renderUI({
HTML(levels(iris$Species))
})
}
# Run the application
shinyApp(ui = ui, server = server)
But all the results are outputed within the same row:
<div id="my_levels_list" class="shiny-html-output shiny-bound-output">setosa versicolor virginica</div>
What I would like to have is something like this instead:
<div id="my_levels_list" class="shiny-html-output shiny-bound-output">
<ul><li>setosa</li> <li>versicolor</li> <li>virginica</li></ul></div>
I tried with more extravagant code like:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Testing shiny App"),
# Show a plot of the generated distribution
mainPanel(
htmlOutput("my_levels_list")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$my_levels_list <- renderUI({
for (i in iris$Species) {
HTML(i)
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
But nothing is outputted.

R Shiny theme colors do not like call to an html page

I have a Shiny app using R code which attempts to use a bootstrap theme bootstrap_united.css:
# ui.R
library(shiny)
#
shinyUI(
fluidPage(
theme = "bootstrap_united.css",
navbarPage("",
tabPanel("Input and display your text",
fluidRow(
column(width = 6,
wellPanel(
h5("Your input ="),
tags$style(type="text/css", "textarea {width:100%}"),
tags$textarea(id = "myText", rows = 22, "")
)
),
column(width = 6,
wellPanel(
h5("Our output ="),
verbatimTextOutput("myText")
)
)
)
),
tabPanel("Help page",
fluidRow(
includeHTML("help.html")
# h5("This works!")
)
)
)
)
)
and
# server.R
library(shiny)
#
shinyServer(
function(input, output) {
output$myText <- renderText({input$myText})
}
)
The second tabPanel attempts to call an html file which is saved in the same folder as the ui.R and server.R files. The call is successful, and the page is displayed, but the presence of this page causes the theme colors from the CSS file to not be shown, and so everything in the R Shiny app is displayed in monochrome shades of gray.
However, if the second tabPanel just displays some text {e.g. shown as # h5("Our output =") in the R code} instead of an html page, then the theme is used/displayed correctly, and the app is displayed in color.
How can I adapt the R code in the shiny app so that the html page will be displayed, and the theme will be displayed correctly too?

how dynamically read image file shiny R

I'm downloading a png image according to user provided input, and I show the image with
mainPanel(
img(src="file.png", height =1187 , width = 748)
)
but, if the user changes the input I have to refresh the page.
The app draft is follows below
the ui
library(shiny)
org <- read.delim("http://rest.kegg.jp/list/organism", header=FALSE)
org <- apply(org[,2:3], 1, function(x) paste(as.matrix(x), collapse="-"))
# Define UI for dataset viewer application
shinyUI(fluidPage(
# Application title
titlePanel("Reactivity"),
# Sidebar with controls to provide a caption, select a dataset, and
# specify the number of observations to view. Note that changes made
# to the caption in the textInput control are updated in the output
# area immediately as you type
sidebarLayout(
sidebarPanel(
textInput("caption", "Caption:", "Data Summary"),
tags$textarea(id="foo", rows=3, cols=40, "Default value"),
selectInput("dataset", "Choose an organism:",
choices = org ),
numericInput("obs", "Number of observations to view:", 10)
),
# Show the caption, a summary of the dataset and an HTML table with
# the requested number of observations
mainPanel(
h3(textOutput("caption")),
verbatimTextOutput("summary"),
tableOutput("view"),
plotOutput('plot1'),
img(src="file.png", height =1187 , width = 748)
)
)
))
and the server
library(shiny)
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
output$caption <- renderText({
cps <- strsplit(input$foo, "\\s+")[[1]]
#tab <- read.table("http://rest.kegg.jp/link/pathway/zma")
#path2cpd <- read.table("http://rest.kegg.jp/link/pathway/compound")
#allmetab <- unique(path2cpd[which(path2cpd[,2] %in% sub("path:zma", "path:map", tab[,2])),])
#cps <- unique(allmetab[,1])
#
url <- "http://www.kegg.jp/kegg-bin/show_pathway?zma00944+default%3dred+"
url <- paste(url, paste(cps, collapse="+"), sep="+")
download.file(url, "form.html")
lines <- readLines("form.html")
imgUrl <- lines[grep('img src="/', lines)]
url <- paste0("http://www.kegg.jp/", strsplit(imgUrl, '"')[[1]][2])
download.file(url, "www/file.png")
url
})
# The output$summary depends on the datasetInput reactive expression,
# so will be re-executed whenever datasetInput is invalidated
# (i.e. whenever the input$dataset changes)
output$plot1 <- renderPlot({
})
})
if you paste the compound codes
C01477
C04608
C04858
C05622
in the box with "Default Value" written I would like to automatically update the picture, or at least have a button to update without having to reload all the app.
If one reloads the navigator one can see the figure with the red dots colored (at the page bottom).
How can I make the function read the image again after a time interval?