[英]Positioning the R shiny selectInput widgets
请运行以下R闪亮脚本,我需要有关将两个selectInputs稍微移到其当前位置上方的帮助。 当前,selectInput下拉列表没有清晰显示。 我尝试使用填充,但没有用。 附加快照以供参考。 请帮助。
## app.R ##
library(shiny)
library(shinydashboard)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "first Chart"),
dashboardSidebar(
width = 0),
dashboardBody(
box(
splitLayout(
cellArgs = list(style = "padding: 2px;padding-top:0px;"),
selectInput("stats1", "", c("Time","Cases"),selected = "Time", width =
"400"),
selectInput("stats2", "", c("Time","Cases"),selected = "Time", width =
"400")),
title = "Sankey Chart", status = "primary",height = "535" ,solidHeader =
T,
plotlyOutput("first_plot"))))
server <- function(input, output)
{
output$first_plot <- renderPlotly({
p <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})
}
shinyApp(ui, server)
这是使用fluidRow
和column
创建UI的另一种方法,我认为可以解决您的问题-下拉菜单现在可以正常工作。 希望这可以帮助!
## app.R ##
library(shiny)
library(shinydashboard)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "first Chart"),
dashboardSidebar(
width = 0),
dashboardBody(
box( title = "Sankey Chart", status = "primary",height = "535" ,solidHeader =
T,
fluidRow(width=12,
column(width=6,
selectInput("stats1", "", c("Time","Cases"),selected = "Time", width =
"400")),
column(width=6,
selectInput("stats2", "", c("Time","Cases"),selected = "Time", width =
"400"))),
fluidRow(
column(width=12,
plotlyOutput("first_plot"))))))
server <- function(input, output)
{
output$first_plot <- renderPlotly({
p <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})
}
shinyApp(ui, server)
在框标题和selectInputs之间使用较少空间的替代方法:
## app.R ##
library(shiny)
library(shinydashboard)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "first Chart"),
dashboardSidebar(
width = 0),
dashboardBody(
box( title = "Sankey Chart", status = "primary",height = "535" ,solidHeader =
T,
div(id='my_div',style='margin-top:-20px;',
fluidRow(width=12,
column(width=6,
selectInput("stats1", "", c("Time","Cases"),selected = "Time", width =
"400")),
column(width=6,
selectInput("stats2", "", c("Time","Cases"),selected = "Time", width =
"400")))),
fluidRow(
column(width=12,
plotlyOutput("first_plot"))))))
server <- function(input, output)
{
output$first_plot <- renderPlotly({
p <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})
}
shinyApp(ui, server)
如果您希望保持原来的方式而不是fluidRow
,则只需更改填充以仅将其添加到底部即可。
library(shiny)
library(shinydashboard)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "first Chart"),
dashboardSidebar(
width = 0),
dashboardBody(
box(
splitLayout(
cellArgs = list(style = "padding: 0px 0px 70px 0px;"),
selectInput("stats1", "", c("Time","Cases"),selected = "Time", width =
"400"),
selectInput("stats2", "", c("Time","Cases"),selected = "Time", width =
"400")),
title = "Sankey Chart", status = "primary",height = "535" ,solidHeader =
T,
plotlyOutput("first_plot"))))
server <- function(input, output)
{
output$first_plot <- renderPlotly({
p <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, 23),
name = "SF Zoo",
type = "bar"
)
})
}
shinyApp(ui, server)
因此,如果您为padding提供4个值而不是1个,则它们将被分配为top
right
bottom
left
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.