在Shiny仪表板上对齐三个元素

时间:2018-04-19 03:34:14

标签: r layout shiny

非常原始的问题,找不到一个好的教程,对我来说很清楚。

我尝试在我的Shiny仪表板上正确放置三个元素

# User interface
ui <- fluidPage(theme = shinytheme("united"),
            titlePanel("Crimes in Washington, DC (2017)"), 
            fluidRow(column(4,
                            selectInput("offenceInput", "Type of Offence",
                                        choices = 
sort(unique(incidents$OFFENSE)),
                                        selected = 
sort(unique(incidents$OFFENSE)),
                                        multiple = TRUE),
                            selectInput("methodInput", "Method of Offence",
                                        choices = 
sort(unique(incidents$METHOD)),
                                        selected = 
sort(unique(incidents$METHOD)),
                                        multiple = TRUE),
                            selectInput("shiftInput", "Police Shift",
                                        choices = 
sort(unique(incidents$SHIFT)),
                                        selected = 
sort(unique(incidents$SHIFT)),
                                        multiple = TRUE),
                            selectInput('background', 'Background',
                                        choices = providers,
                                        multiple = FALSE,
                                        selected = 'Stamen.TonerLite'),
                            dateRangeInput('dateRange',
                                             label = 'Date',
                                             start = as.Date('2017-01-01') , 
end = as.Date('2017-12-31')
                              )
            ),


            column(10,
                   dataTableOutput('my_table'),

            column(12,
                   leafletOutput(outputId = 'map', height = 600)
            )
            )

))

我的地图去了其他地方,我尝试了不同的选择。只需在正确的右上角和下表中绘制地图即可。

由于

奥雷克

Current status

2 个答案:

答案 0 :(得分:2)

希望这有帮助!

在这里,我将所有selectInput字段放在左侧面板中,map放在右侧面板中,my_table放在这两个面板下方。特技是column的第一个参数应该加到12(即顶部面板为4 + 8,底部面板为12)。

ui <- fluidPage(fluidRow(column(4,
                                selectInput(...),
                                selectInput(...),
                                selectInput(...),
                                selectInput(...),
                                dateRangeInput(...)),
                         column(8,
                                leafletOutput(outputId = 'map', height = 600)),
                         column(12,
                                dataTableOutput('my_table'))))

注意:由于缺乏可重复的示例,我无法对其进行测试,但我希望这适用于您的情况。

答案 1 :(得分:0)

在全球RCommunity的帮助下解决。

# User interface
ui <- fluidPage(theme = shinytheme("united"),
            titlePanel(HTML("<h1><center><font size=14> Crimes in Washington, DC (2017) </font></center></h1>")),
            fluidRow(column(4, align="center", 
                            selectInput("offenceInput", "Type of Offence",
                                        choices = sort(unique(incidents$Offense)),
                                        selected = sort(unique(incidents$Offense)),
                                        multiple = TRUE),
                            selectInput("methodInput", "Method of Offence",
                                        choices = sort(unique(incidents$Method)),
                                        selected = sort(unique(incidents$Method)),
                                        multiple = TRUE),
                            selectInput("shiftInput", "Police Shift",
                                        choices = sort(unique(incidents$Shift)),
                                        selected = sort(unique(incidents$Shift)),
                                        multiple = TRUE),
                            selectInput('background', 'Background',
                                        choices = providers,
                                        multiple = FALSE,
                                        selected = 'Stamen.TonerLite'),
                            dateRangeInput('daterangeInput',
                                             label = 'Date',
                                             start = as.Date('2017-01-01') , end = as.Date('2017-12-31')
                              ),
                            br(),
                            plotOutput("bar")
            ),

            column(8,
                   leafletOutput(outputId = 'map', height = 600, width = 800),

                       dataTableOutput('my_table')

            )

))

这给出了以下布局。它很混乱,但结构是我真正想要的。将改进小调整。

enter image description here