My img funcition will not render image in shiny - r

I am trying to use an image as the title instead of text, but all I get in the app is the img icon, not the actual image. Here is my code.
library(tidyverse)
library(leaflet)
library(htmltools)
library(shiny)
ui <- fluidPage(
# Application title
titlePanel(img(src = "www/BBBLogo.png",
height = 40,
width = 60)),
sidebarLayout(
I can't seem to find the issue. Thanks in advance.

You need tags$img and remove www. Try this
ui <- fluidPage(
# Application title
titlePanel(tags$img(src = "BBBLogo.png",
height = 50,
width = 50)),
)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)

Related

What R Shiny layout would allow me to insert a map plot as the background of the entire page?

So think of Google maps.
The map is the entire background with the widgets on the top left corner (that sits on top of the map).
library(shiny)
ui <- fluidPage (
## some layout here
##plotOutput('out_map')
)
server <- function(input, output) {
output$out_map <- shiny::renderPlot(some_dataset)
}
shinyApp(ui = ui, server = server)
You can add some CSS to your map so it takes the whole page. Here is an example using leaflet. Then you can add some absolutePanel() if you want to display some elements on top of the map.
library(shiny)
library(leaflet)
ui <- fluidPage (
# set the height of a #map object with CSS
tags$style(type = "text/css", "#map {height: calc(100vh - 10px) !important;}"),
leafletOutput("map"),
#add some panels above the map
absolutePanel(id = "elements", class = "panel panel-default", top = 0, left = 0, width = 300, height = 300,
tags$p("some other elements"))
)
server <- function(input, output) {
# generate the map with leaflet
output$map <- renderLeaflet({
leaflet() %>% addTiles()
})
}
shinyApp(ui = ui, server = server)

How to put entire image location in tags$img of shiny package?

The following code for tags$img is:
Working...when the image is stored in 'www' folder and src = "Rlogo.png"
Not working...when entire path of the image is given
I need to put the entire location in one of my shiny app where the app.R file will be run from command prompt. Please help thanks..
library(shiny)
ui <- fluidPage(
box(
tags$img(height = 100, width = 100,src = "Rlogo.png"),
tags$img(height = 100, width = 100,src = "E:/myApp/www/Rlogo.png")
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
use imageOutput instead of tags$img:
library(shiny)
ui <- fluidPage(
box(
tags$img(height = 100, width = 100,src = "Rlogo.png"),
imageOutput('image')
)
)
server <- function(input, output, session) {
output$image <- renderImage({
list(src = "E:/myApp/www/Rlogo.png",
alt = "This is alternate text"
)
}, deleteFile = TRUE)
}
shinyApp(ui, server)

How to display image in an infoBox in shiny App?

I am trying to put an image inside the infoBox of a shinyApp.
I am getting this error:
Error in shinyUI(dashboardPage, dashboardHeader("ABC"),
dashboardBody(fluidPage(h1("type"), : unused arguments
(dashboardHeader("ABC"), dashboardBody(fluidPage(h1("type"),
mainPanel(tabsetPanel(tabPanel(h1("summary"), infoBox("BCD", a,
div(img(src = "ribbon.PNG", width = 100), style = "text-align:
center;"))))))))
Code:
library(shiny)
library(shinydashboard)
a = 45
ui < - shinyUI(dashboardPage,
dashboardHeader("ABC"),
dashboardBody(fluidPage(h1("type"),
mainPanel(
tabsetPanel(
tabPanel(h1("summary"),
infoBox("BCD", a, div(img(src = "ribbon.PNG",
width = 100), style = "text-align: center;"))))))))
server <- shinyServer({})
shinyApp(ui, server)
Can anyone help me on this?
Set an image img.png in the www folder and then the code below works :
library(shiny)
library(shinydashboard)
a <- 45
ui <- shinyUI(
dashboardPage(
dashboardHeader(title = "ABC"),
dashboardSidebar(),
dashboardBody(
fluidPage(
infoBox("BCD", a, div(img(src = "img.png", width = 100), style = "text-align: center;"))
)
)
)
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)

Read only indicator in Shiny?

I have an existing Shiny script with standard widgets from the Shiny library. Now I wish to add something to show temperature on a graphical scale? This would be a read-only value, so it wouldn't make sense to use a slider unless the slider can be locked and only changed programatically. Is that possible? If not, what are other suggestions?
To clarify:
Is it possible to have a Shiny slider as read only. The user can not slide it but it can be programmatically changed. Here is a Shiny slider:
library(shiny)
ui <- fluidPage(
sliderInput("aa", "Temp",
min = -20, max = 20,
value = 10, step = 10)
)
server <- function(input, output) { }
shinyApp(ui, server)
I'm not familiar with Shiny Dashboard but I saw taskItem. Can these be "dropped in" and used with a normal Shiny app that uses fluidPage, sidebarPanel, mainPanel? How does one remove the bullet point and the percentage? Here is an example of a taskItem.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
taskItem(value = temp <- 89, color = "red",
"Temp"
))
)
server <- function(input, output) { }
temp <- 89
shinyApp(ui, server)
AFAIK, sliderInput cannot be used as an output. However here's a potential solution using progressBar from shinyWidgets package
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
h3("Sidebar")
),
mainPanel(
br(), br(), br(),
progressBar("tempbar", value = 0, title = "Temperature", status = "danger")
)
)
)
server <- function(input, output, session) {
temp <- 89
updateProgressBar(session, id = "tempbar", value = temp)
}
shinyApp(ui, server)
shiny app with temperature bar
Replace temp in server with whatever calculated value you might have. For fixed temperature value just set it in ui, no need to use updateProgressBar. By default progressBar is scaled from 0-100. To modify see documentation for it.
You can use updateSliderInput to achieve such an behaviour. Couple this with shinyjs::disabled and you get what you want. I would however look for a less hackish solution:
library(shiny)
library(shinyjs)
ui <- fluidPage(
## add style to remove the opacity effect of disabled elements
tags$head(
tags$style(HTML("
.irs-disabled {
opacity: 1
}")
)
),
useShinyjs(),
disabled(sliderInput("aa", "Temp",
min = -20, max = 20,
value = 10, step = 10)),
actionButton("Change", "Change")
)
server <- function(input, output, session) {
observeEvent(input$Change, {
new_temp <- sample(seq(-20, 20, 10), 1)
updateSliderInput(session, "aa", value = new_temp)
})
}
shinyApp(ui, server)

dataTable output within box() in R Shiny: sizing not reactive

I have a dataTable within a box() in my R Shiny app.
When I change the size of the page, the size of the dataTable doesn't change to stay within its box. My plot outputs within the same box have no problem adjusting size, but the data table does.
Thoughts on fixing the data table width?
Here's some code using R's mpg data set to demonstrate my UI issue. Play around with size of window to see the sizing issue I'm referring to.
library(shiny)
library(shinydashboard)
library(data.table)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(width = 325),
dashboardBody(
fluidPage(
box( width = 12,
tabsetPanel(
tabPanel("Summary",
dataTableOutput("coeffTable"))
)
)
)))
server <- function(input, output){
data<-mpg
output$coeffTable<-renderDataTable({
data.table(data[,1:2])
},options = list(lengthMenu = c(5, 10, -1), pageLength = 5))
}
shinyApp(ui = ui, server = server)
This works with the DT package. To use like this:
library(DT)
output$coeffTable <- DT::renderDataTable({...
DT::dataTableOutput("coeffTable")

Resources