请运行下面的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)
答案 0 :(得分:2)
这是使用fluidRow
和column
创建用户界面的另一种方式,我认为这可以解决您的问题 - 下拉菜单现在可以正常使用。希望这有帮助!
## 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)
替代,使用box header和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)
答案 1 :(得分:0)
如果您希望使用原始方式而不是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)
,则只需将填充更改为仅添加到底部。
top
因此,如果您为填充而不是一个提供4个值,则会将其分配为right
bottom
left
<text></text>
。