I built a shiny dashboard and I would like to add some images, here's a reproducible example example using the mtcars
dataset:
library(shiny)
require(shinydashboard)
library(dplyr)
mtcars <- tibble::rownames_to_column(mtcars,"model_car")
#Dashboard header carrying the title of the dashboard
header <- dashboardHeader(title = "mtcars dashboard", titleWidth = 450)
#Sidebar content of the dashboard
sidebar <- dashboardSidebar(
sidebarMenu(
selectInput("model", "Select a model",
choices = mtcars$model_car)
)
)
frow1 <- fluidRow(
valueBoxOutput("value1")
,valueBoxOutput("value2")
,valueBoxOutput("value3")
)
frow2 <- fluidRow(
box(
flexdashboard::gaugeOutput("chart"),width=200,
title="Miles/gallon"
)
)
# combine the two fluid rows to make the body
body <- dashboardBody(frow1, frow2)
#completing the ui part with dashboardPage
ui <- dashboardPage(header, sidebar, body, skin='green')
# create the server functions for the dashboard
server <- function(input, output) {
#creating the valueBoxOutput content
output$value1 <- renderValueBox({
a <- mtcars[mtcars$model_car==input$model,]
b <- a$cyl
shinydashboard::valueBox(
b, "Number of cylinders",icon("stats", lib='glyphicon'),
color = "purple"
)
})
output$value2 <- renderValueBox({
c <- mtcars[mtcars$model_car==input$model,]
d <- c$gear
valueBox(
d, "Number of foward gears",icon("close", lib='font-awesome'),
color = "green"
)
})
output$value3 <- renderValueBox({
e <- mtcars[mtcars$model_car==input$model,]
f <- e$carb
valueBox(
f, "Number of carburetors",icon("calendar", lib='font-awesome'),
color = "orange"
)
})
#creating the plotOutput content
output$chart <- flexdashboard::renderGauge({
x <- mtcars[mtcars$model_car==input$model,]
y <- x$mpg
flexdashboard::gauge(y, min = 0, max = 50, symbol = 'mpg')
})
}
shinyApp(ui, server)
So, I would like to add an image of the selected car, for example, this'd be the image of the first car.
How can I associate an image for each row of the dataset?
And how can I put them on the app?
thanks in advance