fluidRow不会出现在Shiny的mainPanel图形下

时间:2017-01-18 16:47:50

标签: r layout shiny fluid-layout

我使用流畅的网格系统(即使用fluidPage)创建了一个使用sidebarPaneltabsetPanel的Shiny应用程序。除了输入"控制"我放在侧边栏中的小部件,我还想在特定面板的主面板中添加一系列输入小部件 图形。

我的方法是在第一个fluidRow中的plotOutput命令后面添加一个包含多个列的tabPanel

我的代码没有产生任何错误,但出于某种原因没有显示在我主面板的图形下。

这是不可能的,还是我做错了什么?

注意:这个SO question表明我在选项卡中包含多个UI元素的方法是有效的,而SO question表明可以将多个输出添加到mainPanel(但是输入呢? )。那么是什么呢?

具有相同问题的示例代码:

library(shiny)

ui <- fluidPage(

  titlePanel(
    h1("NMS Comparing tool", style = "font-size: 15px")
  ),


  sidebarPanel(width = 3,
           div(style = "font-size: 8px;", 
               sliderInput(inputId = "groups", 
                           label = "No. of Groups",
                           value = 4, min = 2, max = 12)
           ),  

           fluidRow(
             column(6,offset=0,
                    div(style = "height: 105px; padding: 0px 0px",
                        plotOutput(outputId = "scree")
                    )
             ),

             column(6,offset=0,
                    div(style = "font-size: 8px;padding: 0px 10px;height: 105px",
                        checkboxGroupInput(inputId = "labels",
                                           label = "Labels",
                                           choices = c("SPEC","Plot-End","Plot-Start"),
                                           selected = c("SPEC","Plot-End","Plot-Start")
                        )    
                    )
             )
           ),

           fluidRow(
             column(6,offset=0,
                    div(style = "font-size: 8px; padding: 0px 0px",      
                        radioButtons(inputId = "data",
                                     label = "Data",
                                     choices = c("PSP Only","PSP + MAP"),
                                     selected = "PSP + MAP")
                    )    
             ),

             column(6,offset=0,
                    div(style = "font-size: 8px;padding: 0px 10px;",  
                        radioButtons(inputId = "freq",
                                     label = "Frequency",
                                     choices = c(0.025,0.05),
                                     selected = 0.05)
                    )
             )
           ),

           fluidRow(
             column(6,offset=0,
                    div(style = "font-size: 8px; padding: 0px 0px; ",                 
                        radioButtons(inputId = "arrows",
                                     label = "Vector Choice",
                                     choices = c("Cumulative Change","All Samples","Hurricane"),
                                     selected = "Cumulative Change")
                    )
             ),

             column(6,offset=0,
                    div(style = "font-size: 8px;padding: 0px 10px",      
                        selectInput(inputId = "size",
                                    label = "Tree Size",
                                    choices = c("All","Canopy","Subcanopy","Small"),
                                    selected = "All"),
                        tags$style(type = "text/css",
                                   "#size {height: 4px; }")
                    )
             )
           ),

           fluidRow(
             div(style = "font-size: 8px;",                 
                 verbatimTextOutput("info")
             )    
           )
           ,

           mainPanel(width = 9,
                     tabsetPanel(
                       tabPanel(title = "NMS", 
                                plotOutput(outputId = "nms", click = "plot_click"),
                                fluidRow(
                                  column(2,offset=0,
                                         div(style = "font-size: 8px; padding: 0px 0px", 
                                             actionButton(inputId = "plot.singles", label = "Lookup")
                                         )
                                  ),
                                  column(2,offset=0,
                                         div(style = "font-size: 8px; padding: 0px 0px",     
                                             textInput(inputId = "individ", label = "Plot(s)")
                                         )
                                  ),
                                  column(2,offset=0,
                                         div(style = "font-size: 8px; padding: 0px 0px", 
                                             textInput(inputId =  "group.choose", label = "Group(s)")
                                         )
                                  ),
                                  column(3,offset=0,
                                         div(style = "font-size: 8px; padding: 0px 0px", 
                                             sliderInput(inputId = "lwidth.choose", label = "LineWidth",min = 1, max = 6)
                                         )
                                  )
                                )
                       ),
                       tabPanel(title = "Silhouette", plotOutput(outputId = "silhouette")),
                       tabPanel(title = "Indicator Spp", dataTableOutput(outputId = "ind.spp")),
                       tabPanel(title = "Data", dataTableOutput(outputId = "nms.data.table"))
                     )
           )
  )
)


server <- function(input, output) {

 output$scree <- renderPlot({

    par(mar = c(1.5,1.4,0.1,0.1), mgp = c(0.5,0.01,0), tcl = -0.1)
    plot(runif(99),runif(99),cex.axis=0.5,cex.lab=0.5,cex=0.75)

  },height = 95, width = 135) 

  output$nms <- renderPlot({

    plot(runif(99),runif(99))

  })

}

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:3)

当然,您尝试做的事情是可能的。当我运行您的示例代码时,我实际上确实看到了绘图下的小部件(查找,绘图,组等)。但我必须首先解决一些小问题 - 首先,你需要给sliderInput一个值。另一方面,你有一个错位的括号导致mainPanel被推入你的sidebarPanel

但是你的fluidRow本身并没有问题。确保您已将其放在用户界面中的正确位置。