Created
June 21, 2018 23:18
-
-
Save tmastny/0e32a6945cd0ac2e234575f9c3beef2b to your computer and use it in GitHub Desktop.
Shifted Coordinate Values in Shiny App due to outer margins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- basicPage( | |
HTML("oma"), | |
numericInput("oma_one", "bottom", value = 0), | |
numericInput("oma_two", "left", value = 0), | |
numericInput("oma_three", "top", value = 0), | |
numericInput("oma_four", "right", value = 0), | |
plotOutput("plot1", | |
click = "plot_click", | |
dblclick = "plot_dblclick", | |
hover = "plot_hover", | |
brush = "plot_brush" | |
), | |
verbatimTextOutput("info_oma"), | |
HTML("omi"), | |
numericInput("omi_one", "bottom", value = 0.5), | |
numericInput("omi_two", "left", value = 0.5), | |
numericInput("omi_three", "top", value = 0.5), | |
numericInput("omi_four", "right", value = 0.5), | |
plotOutput("plot2", | |
click = "plot_click", | |
dblclick = "plot_dblclick", | |
hover = "plot_hover", | |
brush = "plot_brush" | |
), | |
verbatimTextOutput("info_omi"), | |
HTML("omd"), | |
numericInput("omd_one", "bottom", value = 0.15), | |
numericInput("omd_two", "left", value = 0.85), | |
numericInput("omd_three", "top", value = 0.15), | |
numericInput("omd_four", "right", value = 0.85), | |
plotOutput("plot3", | |
click = "plot_click", | |
dblclick = "plot_dblclick", | |
hover = "plot_hover", | |
brush = "plot_brush" | |
), | |
verbatimTextOutput("info_omd"), | |
HTML("mar"), | |
numericInput("mar_one", "bottom", value = 5.1), | |
numericInput("mar_two", "left", value = 4.1), | |
numericInput("mar_three", "top", value = 4.1), | |
numericInput("mar_four", "right", value = 2.1), | |
plotOutput("plot4", | |
click = "plot_click", | |
dblclick = "plot_dblclick", | |
hover = "plot_hover", | |
brush = "plot_brush" | |
), | |
verbatimTextOutput("info_mar"), | |
HTML("mai"), | |
numericInput("mai_one", "bottom", value = 2), | |
numericInput("mai_two", "left", value = 2), | |
numericInput("mai_three", "top", value = 2), | |
numericInput("mai_four", "right", value = 2), | |
plotOutput("plot5", | |
click = "plot_click", | |
dblclick = "plot_dblclick", | |
hover = "plot_hover", | |
brush = "plot_brush" | |
), | |
verbatimTextOutput("info_mai") | |
) | |
server <- function(input, output) { | |
output$plot1 <- renderPlot({ | |
par(oma = c(input$oma_one, input$oma_two, input$oma_three, input$oma_four)) | |
plot(mtcars$wt*100, mtcars$mpg) | |
}) | |
output$plot2 <- renderPlot({ | |
par(omi = c(input$omi_one, input$omi_two, input$omi_three, input$omi_four)) | |
plot(mtcars$wt*100, mtcars$mpg) | |
}) | |
output$plot3 <- renderPlot({ | |
par(omd = c(input$omd_one, input$omd_two, input$omd_three, input$omd_four)) | |
plot(mtcars$wt*100, mtcars$mpg) | |
}) | |
output$plot4 <- renderPlot({ | |
par(mar = c(input$mar_one, input$mar_two, input$mar_three, input$mar_four)) | |
plot(mtcars$wt*100, mtcars$mpg) | |
}) | |
output$plot5 <- renderPlot({ | |
par(mai = c(input$mai_one, input$mai_two, input$mai_three, input$mai_four)) | |
plot(mtcars$wt*100, mtcars$mpg) | |
}) | |
output$info_oma <- renderText({ | |
xy_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n") | |
} | |
xy_range_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("xmin=", round(e$xmin, 1), " xmax=", round(e$xmax, 1), | |
" ymin=", round(e$ymin, 1), " ymax=", round(e$ymax, 1)) | |
} | |
paste0( | |
"click: ", xy_str(input$plot_click), | |
"dblclick: ", xy_str(input$plot_dblclick), | |
"hover: ", xy_str(input$plot_hover), | |
"brush: ", xy_range_str(input$plot_brush) | |
) | |
}) | |
output$info_omi <- renderText({ | |
xy_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n") | |
} | |
xy_range_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("xmin=", round(e$xmin, 1), " xmax=", round(e$xmax, 1), | |
" ymin=", round(e$ymin, 1), " ymax=", round(e$ymax, 1)) | |
} | |
paste0( | |
"click: ", xy_str(input$plot_click), | |
"dblclick: ", xy_str(input$plot_dblclick), | |
"hover: ", xy_str(input$plot_hover), | |
"brush: ", xy_range_str(input$plot_brush) | |
) | |
}) | |
output$info_omd <- renderText({ | |
xy_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n") | |
} | |
xy_range_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("xmin=", round(e$xmin, 1), " xmax=", round(e$xmax, 1), | |
" ymin=", round(e$ymin, 1), " ymax=", round(e$ymax, 1)) | |
} | |
paste0( | |
"click: ", xy_str(input$plot_click), | |
"dblclick: ", xy_str(input$plot_dblclick), | |
"hover: ", xy_str(input$plot_hover), | |
"brush: ", xy_range_str(input$plot_brush) | |
) | |
}) | |
output$info_mar <- renderText({ | |
xy_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n") | |
} | |
xy_range_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("xmin=", round(e$xmin, 1), " xmax=", round(e$xmax, 1), | |
" ymin=", round(e$ymin, 1), " ymax=", round(e$ymax, 1)) | |
} | |
paste0( | |
"click: ", xy_str(input$plot_click), | |
"dblclick: ", xy_str(input$plot_dblclick), | |
"hover: ", xy_str(input$plot_hover), | |
"brush: ", xy_range_str(input$plot_brush) | |
) | |
}) | |
output$info_mai <- renderText({ | |
xy_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("x=", round(e$x, 1), " y=", round(e$y, 1), "\n") | |
} | |
xy_range_str <- function(e) { | |
if(is.null(e)) return("NULL\n") | |
paste0("xmin=", round(e$xmin, 1), " xmax=", round(e$xmax, 1), | |
" ymin=", round(e$ymin, 1), " ymax=", round(e$ymax, 1)) | |
} | |
paste0( | |
"click: ", xy_str(input$plot_click), | |
"dblclick: ", xy_str(input$plot_dblclick), | |
"hover: ", xy_str(input$plot_hover), | |
"brush: ", xy_range_str(input$plot_brush) | |
) | |
}) | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment