我想將一組檔案輸入成對并排放置。但是,它們被放置在另一個下方。
我嘗試在用戶界面內做:
box(
div(style="display:inline-block", fileInput("file1", "File 1")),
div(style="display:inline-block", fileInput("file2", "File 2"))
)
但失敗了。
我還嘗試將 fileInput 小部件的寬度更改為更小,但這也不起作用。我看過其他例子,但有不同的小部件,解決它的方法是使用div(style="display:inline-block")格式。
這就是為什么我問這個小部件是否可以做我想做的事情。
可重現的例子:
這是一個可重現的示例:
library(shiny)
library(shinydashboard)
## Header
Header = dashboardHeader(title = "Help! :(", titleWidth = 250)
## Sidebar
SideBar = dashboardSidebar(sidebarMenu(menuItem(text = "Help me please",tabName = "Menu", startExpanded = TRUE)))
## Tab & Body
Tab = tabItem(tabName = "Menu",
fluidRow(
box(
title = "Import Data",
solidHeader = TRUE,
collapsible = TRUE,
width = 12,
fileInput(inputId = "file1",
label = "File 1",
multiple = TRUE,
accept = c(".xlsx", ".txt"),
width = '30%'),
fileInput(inputId = "file2",
label = "File 2",
multiple = TRUE,
accept = c(".xlsx", ".txt"),
width = '30%')
)
))
Body = dashboardBody(tabItems(Tab))
## UI
ui = dashboardPage(header = Header,
sidebar = SideBar,
body = Body,
skin = "red")
## Server
server = function(input, output, session){
}
## ShinyApp
shinyApp(ui,server)
uj5u.com熱心網友回復:
使用shinydashboard基于列和行的布局:
library(shiny)
library(shinydashboard)
## Header
Header = dashboardHeader(title = "Help! :(", titleWidth = 250)
## Sidebar
SideBar = dashboardSidebar(sidebarMenu(menuItem(text = "Help me please",tabName = "Menu", startExpanded = TRUE)))
## Tab & Body
Tab = tabItem(tabName = "Menu",
fluidRow(
box(
title = "Import Data",
solidHeader = TRUE,
collapsible = TRUE,
width = 12,
fluidRow(
column(width = 3,
fileInput(inputId = "file1",
label = "File 1",
multiple = TRUE,
accept = c(".xlsx", ".txt"))
),
column(width = 3,
fileInput(inputId = "file2",
label = "File 2",
multiple = TRUE,
accept = c(".xlsx", ".txt"))
)
),
fluidRow(
column(width = 3,
fileInput(inputId = "file3",
label = "File 3",
multiple = TRUE,
accept = c(".xlsx", ".txt"))
),
column(width = 3,
fileInput(inputId = "file4",
label = "File 4",
multiple = TRUE,
accept = c(".xlsx", ".txt"))
)
)
))
)
Body = dashboardBody(tabItems(Tab))
## UI
ui = dashboardPage(header = Header,
sidebar = SideBar,
body = Body,
skin = "red")
## Server
server = function(input, output, session){
}
## ShinyApp
shinyApp(ui,server)
uj5u.com熱心網友回復:
你幾乎做到了!使用您可以添加的 HTML/CSS 解決它,float: left以便您可以并排放置框,因為默認情況下 HTML div 是堆疊的。您還想在 div 之間添加邊距。min-width確保整個事情反應更靈敏。當視口變得太窄時,布局會將第二個包裹在第一個fileInput下方。
library(shiny)
library(shinydashboard)
## Header
Header = dashboardHeader(title = "Help! :(", titleWidth = 250)
## Sidebar
SideBar = dashboardSidebar(sidebarMenu(menuItem(text = "Help me please",tabName = "Menu", startExpanded = TRUE)))
## Tab & Body
Tab = tabItem(tabName = "Menu",
fluidRow(
box(
title = "Import Data",
solidHeader = TRUE,
collapsible = TRUE,
width = 12,
div(
fileInput(inputId = "file1",
label = "File 1",
multiple = TRUE,
accept = c(".xlsx", ".txt")),
style="min-width:200px;max-width:45%; float:left; margin-right:2.5%"),
div(
fileInput(inputId = "file2",
label = "File 2",
multiple = TRUE,
accept = c(".xlsx", ".txt")),
style="min-width:200px;max-width:45%; float:left")
)))
Body = dashboardBody(tabItems(Tab))
## UI
ui = dashboardPage(header = Header,
sidebar = SideBar,
body = Body,
skin = "red")
## Server
server = function(input, output, session){
}
## ShinyApp
shinyApp(ui,server)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/318526.html
