'Shiny: Improve / format text output of verbatimTextOutput()
I have
library(shiny)
ui <- fluidPage(
# App title ----
titlePanel("Interactive CLicks"),
br(),
fluidRow(
br(),
verbatimTextOutput("info_hover"),
plotOutput(outputId = "distPlot",hover = "plot_hover",click= "plot_click", dblclick = "plot_db_click",height = 500, width = 1600 ),
br(),
verbatimTextOutput("info_click"),
verbatimTextOutput("info_db_click"),
verbatimTextOutput("double_to_single_click"))
)
## server.R
server <- function( input, output, session){
#Click Points
single.source_coords <- reactiveValues(xy=data.frame(x=c(1,1), y=c(1,1)))
double.source_coords <- reactiveValues(xy=data.frame(x=c(1,1), y=c(1,1)))
observeEvent(input$plot_click, {
single.source_coords$xy[2,] <- c(input$plot_click$x, input$plot_click$y)
})
observeEvent(input$plot_db_click, {
double.source_coords$xy[2,] <- c(input$plot_db_click$x, input$plot_db_click$y)
})
## RenderPlot
output$distPlot <- renderPlot({
plot(1, 1,
xlim=c(0,10), ylim=c(0,10))
#Click points
points( single.source_coords$xy[2,1], single.source_coords$xy[2,2], cex=3, pch=17)
points( double.source_coords$xy[2,1], double.source_coords$xy[2,2], cex=3, pch=17)
segments(x0 =single.source_coords$xy[2,1], y0 = single.source_coords$xy[2,2], x1 = double.source_coords$xy[2,1], y1 = double.source_coords$xy[2,2], col = "darkred", lwd = 2, lty = 3)
})
output$info_click <- renderText({
paste0("Single Click Multiple", "\nX=", single.source_coords$xy[2,1], " Y= ",single.source_coords$xy[2,2], "\nX=", round(single.source_coords$xy[2,1],4), " Y= ",round(single.source_coords$xy[2,2], 5))
})
output$info_db_click <- renderText({
paste0("Double Multiple", "\nX=", double.source_coords$xy[2,1], " Y= ",double.source_coords$xy[2,2], "\nX=", round(double.source_coords$xy[2,1],2), " Y= ",round(double.source_coords$xy[2,2],4))
})
output$info_hover <- renderText({
paste0("Hover Multiple", "\nX=", input$plot_hover$x*2, " Y= ",input$plot_hover$y*2, "\nThis is X=", round(input$plot_hover$x*2,5), " not A but Y= ",round(input$plot_hover$y*2,4))
})
}
### Run Application
shinyApp(ui, server)
In the 3 output areas of verbatimTextOutput() because of the different length of the labels and the outputs the result of the verbatimTextOutput() looks awful
Is there any way to align Labels and Outputs so that it is more aesthetically pleasing? I like the compactness of verbatimTextOutput() I would not like to go to a table output. I would just like to find a way to improve the formatting of verbatimTextOutput().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

