【问题标题】:Arrange R shiny Side bar objects排列 R 闪亮的侧边栏对象
【发布时间】:2018-09-20 21:28:07
【问题描述】:

我使用 R shiny 创建了以下界面。

  library(shiny)




  ui <- fluidPage(
  #Can be fluid row also
  fluidRow(
  column(3,
       h3("Excel DB"),
       hr(),
       fileInput("file1", "Excel DB",
                 multiple = TRUE,
                 accept = c("text/csv/xlsx/xls",
                            "text/comma-separated-values,text/plain",
                            ".csv", ".xls", ".xlsx")),
       textInput(inputId = 'Type',label =  'Type'),
       textInput(inputId = 'Client',label =  'Client'),
       textInput(inputId = "Task", label = "Task"),
       actionButton(inputId = "ClearAll", label = "Clear Screen"),
       radioButtons("dist", "Vertical Axis Scale",
                    c("Linear" = "Linear Regression",
                      "Log" = "Logistic Regression"))
),
column(5,h5('              '),
       hr(), downloadButton(outputId = "Downloaddata", label = "Fetch Dataset"),
       textInput(inputId = "Commodity", label = "Commodity"),
       textInput(inputId = "Year", label = "Year"),
       radioButtons("dist", "Horizontal Axis Scale",
                    c("Linear" = "Linear Regression",
                      "Log" = "Logistic Regression")),
       numericInput(inputId = "Numberinput", label = "Numinput", min = -1000000000, max = 1000000000, value = 0,step = 1)

)
), sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100, step 
= 2.5, value = 1)
)

我创建了以下空服务器

server<-function(input, output){}
shinyApp(ui, server)

上面的代码创建了一个闪亮的应用程序,它的侧边栏面板有两列。但是,2 列彼此不对齐。我想知道如何安排应用程序的组件如下。

获取数据集按钮应位于浏览按钮旁边。同样,商品文本框应该在类型文本框旁边,年份框应该靠近客户端。两组单选按钮应相互对齐。我在这里请求一些帮助。我无法按那种模式排列它们

【问题讨论】:

    标签: r shiny sidebar


    【解决方案1】:

    要实现这一点,您需要对column()fluidRow() 进行一些嵌套。 This answer 的解释足以让您入门,以及 Shiny's layout guide 上的示例。我相信以下内容应该可以大致满足您的需求:

    library(shiny)
    
    ui <- fluidPage(
      #Can be fluid row also
      h3("Excel DB"),
      hr(),
      fluidRow(
        column(12,
               fluidRow(
                 column(3,
                        fileInput("file1", NULL,
                                  multiple = TRUE,
                                  accept = c("text/csv/xlsx/xls",
                                             "text/comma-separated-values,text/plain",
                                             ".csv", ".xls", ".xlsx"))),
                 column(5,
                        column(3,
                               downloadButton(outputId = "Downloaddata", label = "Fetch Dataset")),
                        column(2, offset = 2,
                               actionButton(inputId = "ClearAll", label = "Clear Screen"))
                        )
               ),
               fluidRow(
                 column(3,
                        textInput(inputId = 'Type',label =  'Type'),
                        textInput(inputId = 'Client',label =  'Client'),
                        textInput(inputId = "Task", label = "Task")
                 ),
                 column(5,
                        textInput(inputId = "Commodity", label = "Commodity"),
                        textInput(inputId = "Year", label = "Year"),
                        numericInput(inputId = "Numberinput", label = "Numinput", min = -1000000000, max = 1000000000, value = 0,step = 1)
                 )),
               fluidRow(
                 column(3,
                        radioButtons("dist", "Vertical Axis Scale",
                                     c("Linear" = "Linear Regression",
                                       "Log" = "Logistic Regression"))),
                 column(5,
                        radioButtons("dist", "Horizontal Axis Scale",
                                     c("Linear" = "Linear Regression",
                                       "Log" = "Logistic Regression")))
                 ),
               fluidRow(
                 column(5,
                        sliderInput(inputId = "Scale", label = "Scale", min = 0, max = 100, 
                                    step = 2.5, value = 1)) 
                 )
               )
        )
      )
    

    reprex package (v0.2.1) 于 2018 年 9 月 20 日创建

    【讨论】:

    • 谢谢。效果很好。它还解释了如何通过嵌套更改侧边栏布局。再次感谢楼主
    猜你喜欢
    • 2020-09-20
    • 2019-11-13
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 2017-04-23
    • 2016-11-11
    相关资源
    最近更新 更多