我已经在R闪亮中生成了两个图,但目前这两个图重叠在一起。我怎样才能调整它们之间的距离?这是我的ui.R和server.R代码以及从相同的
生成的图片ui.R
library(shiny)
library(leaflet)
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput("n", label = "Select K for display", choices = c("2", "3", "4")),
checkboxInput("show", "Flood_path")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("preImage"),
leafletOutput("map")
)
)
))
server.R
library(shiny)
shinyServer(function(input, output, session) {
output$preImage <- renderImage({
# When input$n is 3, filename is ./images/image3.jpeg
filename <- normalizePath(file.path('./images', paste('image', input$n, '.jpeg', sep='')))
# Return a list containing the filename and alt text
list(src = filename, alt = paste("Image number", input$n))
}, deleteFile = FALSE)
# Switch for Structure
dt <- reactive(
switch(input$n,
"2" = data_K2$Structure.2,
"3" = data_K2$Structure.3,
"4" = data_K2$Structure.4))
# Map
output$map <- renderLeaflet(
leaflet(data = data_K2) %>% addTiles() %>% setView(lng = mean(data_K2$Long), lat = mean(data_K2$Lat), zoom = 4) %>%
addCircleMarkers(lat = ~Lat, lng = ~Long, popup = ~Location_discription, radius=2, color = ~dt(), fill = TRUE) %>%
addPolylines(group="markers", lng = data_fp$Long, lat = data_fp$Lat, col = "red", weight = 2, opacity = 0.5)
)
答案 0 :(得分:0)
我会使用fluidrow:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
fluidRow(column(12,
fluidRow(
column(2,
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
),
column(10, plotOutput("distPlot"))
),
fluidRow(column(2),
column(10, plotOutput("distPlot2")))
)
)
)
# 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$distPlot2 <- 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')
})
}
# Run the application
shinyApp(ui = ui, server = server)
我刚刚意识到这篇文章有多久了。