One slight modification I'd make to @nirgrahamuk 's excellent response would be to specify text-align: center; for the div() and the textOutput(), which will help if values are longer than a couple of characters (which may not be the case). This also requires the textOutput() width to be set to match the width of the image. Updated code below.
library(shiny)
# Define UI
ui <- fluidPage(
# Application title
titlePanel("Count"),
# Sidebar
sidebarLayout(
sidebarPanel(
textInput("txt", "Enter the text to display below:",
value = 52
)
),
# Show an image with a counter
mainPanel(
fluidRow(
column(
12,
div(
style = "
margin-left:36%;
display: inline-block;
text-align: center;
position: absolute;
",
img(
src = "https://forum.posit.co/uploads/default/original/3X/5/1/51436f1a309c3aaeb71f5f580182029f2733a301.jpeg",
height = 100,
width = 100,
style = " position: relative;"
),
span(textOutput("default"),
style = "
color: orange;
position: relative;
text-align: center;
width: 100px;
top: -80px;
"
)
)
)
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$default <- renderText({
input$txt
})
}
# Run the application
shinyApp(ui = ui, server = server)