我有一个 R Shiny 应用程序,带有不同的下载按钮,如下面的代码所示。问题在于,fluidRow 中下载按钮的位置不会自动与其他输入元素(例如下面的 dateInput)的位置对齐。
ui <- dashboardPage(
title = "Test Dashboard", # this is the name of the tab in Chrome browserr
dashboardHeader(title = "Web Portal"),
dashboardSidebar(
sidebarMenu(
menuItem('Retail', tabName = "retail", icon = icon("th"),
menuItem('Dashboard', tabName = 'retail_dashboard'))
)
),
dashboardBody(
tabItem(tabName = "retail_dashboard",
tabsetPanel(type = "tabs",
tabPanel("Dashboard",
h3("Test."),
fluidRow(column(2,
dateInput("idx_muni_tot_ret_start_dt", label = "Start Date:", value = Sys.Date()-10)), # 1yr ago
column(2,
dateInput("idx_muni_tot_ret_end_dt", label = "End Date:", value = Sys.Date())),
column(2,
downloadButton("download_idx_muni_TR_data","Download Data"))
)
)
)
)
)
)
server <- function(input, output, session) {
# code...
}
cat("\nLaunching 'shinyApp' ....")
shinyApp(ui, server)
我在这里发现了类似的问题How do I align downloadButton and ActionButton in R Shiny app?在这里 Change download button position in a tab panel in shiny app但他们似乎没有回答我的问题。我还附上了一张屏幕截图,其中包含当前按钮位置以及预期按钮位置。
最佳答案
解决方法是在下载按钮顶部模拟标签并添加 5px 的 margin-bottom。
column(
width = 2,
div(tags$label(), style = "margin-bottom: 5px"),
div(downloadButton("download_idx_muni_TR_data", "Download Data"))
)
关于R Shiny 的下载按钮与其他输入元素(如 dateInput)对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75210155/