【发布时间】:2022-01-22 00:51:26
【问题描述】:
我很难理解关于这个问题的那些深入研究 CSS/java 脚本的帖子,我对此知之甚少。
在运行下面的代码时,我试图让下载按钮、要查看的表格行数和过滤器整齐地呈现。有人知道怎么做吗?
我故意使用fluidRow(column(width...)) 将它们挤在下面,以更好地说明问题,因为在更完整的应用程序中,这源自表格在狭窄的主面板中呈现。请查看底部的图片以了解一些清理此问题的想法:通过缩小下载按钮的大小、减少显示输入行数中的文本等。我愿意接受任何其他格式建议!虽然我不想减少项目(下载按钮、长度、过滤器)。
library(dplyr)
library(DT)
library(shiny)
library(shinyWidgets)
library(tidyverse)
ui <-
fluidPage(
fluidRow(
column(width = 8,
h3("Data table:"),
tableOutput("data"),
h3("Sum the data table columns:"),
radioButtons(
inputId = "grouping",
label = NULL,
choiceNames = c("By period 1", "By period 2"),
choiceValues = c("Period_1", "Period_2"),
selected = "Period_1",
inline = TRUE
),
DT::dataTableOutput("sums")
)
)
)
server <- function(input, output, session) {
data <- reactive({
data.frame(
Period_1 = c("2020-01", "2020-02", "2020-03", "2020-01", "2020-02", "2020-03"),
Period_2 = c(1, 2, 3, 3, 1, 2),
ColA = c(1000.01, 20, 30, 40, 50, 60),
ColB = c(15.06, 25, 35, 45, 55, 65)
)
})
summed_data <- reactive({
data() %>%
group_by(!!sym(input$grouping)) %>%
select("ColA","ColB") %>%
summarise(across(everything(), sum))
})
output$data <- renderTable(data())
output$sums <- renderDT({ # this section changed
summed_data() %>%
datatable(rownames = FALSE) %>%
formatCurrency(c("ColA", "ColB"), currency = '\U20AC', digits = 2)
})
output$sums <- renderDT({
summed_data() %>%
datatable(rownames = FALSE,
extensions = 'Buttons',
options = list(
buttons = list(
list(extend = 'copy', filename = "flowsBalances"),
list(extend = 'csv', filename = "flowsBalances"),
list(extend = 'excel', filename = "flowsBalances")
),
dom = 'Blfrtip'
),
class = "display"
) %>%
formatCurrency(c("ColA", "ColB"), currency = '', digits = 2)
})
}
shinyApp(ui, server)
【问题讨论】: