Hi,
I use the following code to center text in a well panel in several shiny apps:
tags$head(tags$style(HTML("
#auc {
text-align: center;
#texto {
text-align: center;
}
}"))),
but the script file in RStudio 1.2.5019 doesn't run (hitting ctrl-enter), only when I rename the whole Script file to "app.R" and click on "run App". If I remove the above snippet, then it runs, but the text is no longer centered in the well panel. This does not happen with RStudio 1.2.1335.
I use Windows 10 home single language, version 1903. Please help.
Thanks.
Luis
REPREX:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
tags$head(tags$style(HTML("
#auc {
text-align: center;
}"))),
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
fluidRow(column(width = 8, offset = 2,
h4(htmlOutput(outputId = "auc"))
))
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$auc <- renderUI({
wellPanel(
HTML( "<h4>" ,"Text to be centered","</h4>",
'<p><span style="color: #ff0000;">',
"Result to be centered",'</span></p>')
)
})
}
# Run the application
shinyApp(ui = ui, server = server)