2017-06-27 143 views
1

让我们假设我有一个非常简单的应用程序,只有8个输入分组在2个面板(4输入| 4输入 - 见图片波纹管),并基于这些,我绘制一个小图(容易peasy )。闪亮:标签位置,文本输入

The panel I want to make

,我所面临的问题是,我想有标签只提供给第一面板,并在textInput框的左侧。

例如(请原谅我的草率的图像编辑!)

enter image description here

什么建议吗?

我对图1输出MWE:

library(shiny) 
ui<-shinyUI(fluidPage(
    wellPanel(
    tags$style(type="text/css", '#leftPanel { max-width:300px; float:left;}'), 
    id = "leftPanel", 
    textInput("Population1000", 'Population 1000',"15"), 
    textInput("Area1000",'Area 1000', "20"), 
    textInput("GNI1000", 'GNI 1000', "2314"), 
    textInput("GDP1000", "GDP 1000", "1000") 
), 
    wellPanel(
    tags$style(type="text/css", '#RightPanel { max-width:300px; float:left;}'), 
    id = "RightPanel", 
    textInput("Population2000", 'Population 2000',"15"), 
    textInput("Area2000",'Area 2000', "20"), 
    textInput("GNI2000", 'GNI 2000', "2314"), 
    textInput("GDP2000", "GDP 2000", "1000") 
) 
) 
) 
server<-shinyServer(function(input, output) {NULL}) 
shinyApp(ui,server) 

回答

3

嗨,你可以尝试使用引导的horizontal form,看看下面的代码,它创建的每个宽度4 3列。您可以在class = "col-sm-4 control-label"中更改标签的宽度,并在width = 4中更改输入的宽度。

library("shiny") 
ui <- fluidPage(

    fluidRow(
    column(

     width = 4, 

     tags$form(
     class="form-horizontal", 

     tags$div(
      class="form-group", 
      tags$label(class = "col-sm-4 control-label", `for` = "Population1000", br(), "Population"), 
      column(width = 4, textInput(inputId = "Population1000", label = "Year 1000", value = "15")), 
      column(width = 4, textInput(inputId = "Population2000", label = "Year 2000", value = "15")) 
     ), 

     tags$div(
      class="form-group", 
      tags$label(class = "col-sm-4 control-label", `for` = "Area1000", "Area"), 
      column(width = 4, textInput(inputId = "Area1000", label = NULL, value = "20")), 
      column(width = 4, textInput(inputId = "Area2000", label = NULL, value = "20")) 
     ), 

     "..." 

    ) 
    ) 
) 

) 

server <- function(input, output) { 

} 

shinyApp(ui = ui, server = server) 

结果:

enter image description here

PS:你不应该使用相同的ID进行输入。

+0

嗨@Victorp,这确实是一个非常好的解决方案,但它不能解决我的问题,因为我无法在面板中对条目进行分组 - 或类似的东西。基本上,每列应该代表一年(例如1000,2000),因此应该有区分列的方法(例如标题)。 (对不起,我不会在图片中使它更清晰,我会做出更改) –

+1

最简单的方法是在第一个输入中放置一个标签,并在左侧的标签中添加换行符。查看编辑 – Victorp

+0

精彩的,测试它,它的工作方式非常好。 –