I have
library(shiny)
ui <- fluidPage(
# App title ----
titlePanel("Interactive CLicks"),
br(),
fluidRow(
br(),
plotOutput(outputId = "distPlot",hover = "plot_hover",click= "plot_click", dblclick = "plot_db_click",height = 500, width = 1600 )),
br(),
fluidRow(column(width = 12), verbatimTextOutput("info_hover"),
fluidRow(column(6, verbatimTextOutput("info_click")), column(6, offset = 6, 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])
})
output$info_db_click <- renderText({
paste0("Double Click Multiple", "\nX=", double.source_coords$xy[2,1], " Y= ",double.source_coords$xy[2,2])
})
output$info_hover <- renderText({
paste0("Hover Click Multiple", "\nX=", input$plot_hover$x*2, " Y= ",input$plot_hover$y*2)
})
output$double_to_single_click <- renderText({
paste0("Double to Signle", "\nX=", double.source_coords$xy[2,1]/single.source_coords$xy[2,1], " Y= ",double.source_coords$xy[2,2]/single.source_coords$xy[2,2])
})
}
### Run Application
shinyApp(ui, server)
i would like to have the single click multiple
and double click multiple
verbatimTextOutput()
boxes side by side. What am I doing wrong?
If I replace with
fluidRow(column(width = 12), "info_hover",
fluidRow(column(6, "info_click"), column(6, offset = 6, "info_db_click")),
"double_to_single_click")
it seems to be working.
CodePudding user response:
Removing offset
seems to give the desired result, given that according to the documentation, offset is the number of columns to offset from the end of the previous column.
fluidRow(column(width = 12), verbatimTextOutput("info_hover"),
fluidRow(column(6, verbatimTextOutput("info_click")), column(6, verbatimTextOutput("info_db_click"))),
verbatimTextOutput("double_to_single_click"))
CodePudding user response:
The syntax for fluidRow
is:
fluidRow(
column(
width = 6,
UI elements in the column (comma-separated if multiple)
),
column(
width = 6,
UI elements in the column (comma-separated if multiple)
)
)
So you need to do:
fluidRow(
column(
width = 6,
verbatimTextOutput("xxx")
),
column(
width = 6,
verbatimTextOutput("yyy")
)
)