R Shiny应用程序中splitlayout中的两个框未对齐。我该如何解决?

时间:2019-04-01 15:12:12

标签: r shiny shinydashboard

我有两个numericInput框,用于输入数字变量的最小值和最大值(范围)。我尝试使用splitLayout,该方法可以正常工作,但是当我为框添加标签时,框未对齐。

下面的代码

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 
sidebarLayout(
    sidebarPanel(
        sliderInput("bins",
                    "Number of bins:",
                    min = 1,
                    max = 50,
                    value = 30)
    ),

    # Show a plot of the generated distribution
    mainPanel(

        #fluidRow(
        splitLayout(

            variable <- faithful$waiting,

            numericInput(paste("Min"), 
                         #round = TRUE,
                         label = h5(c("test")),
                         min = round(min(variable, na.rm=TRUE)),
                         max = round(max(variable, na.rm=TRUE))-1,
                         value = round(min(variable, na.rm=TRUE))

            ), ## end slider input

            numericInput(paste("Min"), 
                         #round = TRUE,
                         label = h5(""),
                         min = round(min(variable, na.rm=TRUE))+1,
                         max = round(max(variable, na.rm=TRUE)),
                         value = round(max(variable, na.rm=TRUE))


            )
    )
)
))

# 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')
})
}

# Run the application 
shinyApp(ui = ui, server = server)

如果运行代码,您将看到框未对齐。

我该如何解决?

1 个答案:

答案 0 :(得分:1)

问题是您有一个框的标签,该标签将其向下推,而另一框没有等效的标签。要向下推第二个框,您需要包含一些内容,这些内容将被读为标签,但不显示任何内容。我使用HTML中断:

 numericInput(paste("Min"), 
                     #round = TRUE,
                     label = h5(HTML("<br/>")),
                     min = round(min(variable, na.rm=TRUE))+1,
                     max = round(max(variable, na.rm=TRUE)),
                     value = round(max(variable, na.rm=TRUE))