下面的代码允许用户:
1.登录(用户名“a”和密码“a”)
1.显示一个用户将上传CSV文件的应用程序,然后单击“生成报告”按钮。此操作将使用上传的CSV文件编织Rmarkdown。
1.报告准备就绪后,用户将使用“下载报告”按钮下载报告。
一切正常,除了第二步页面顶部出现的空白。我是新来的闪亮,所以有人能帮助我理解为什么有空白的空间,以及我如何才能摆脱它?
x1c 0d1x的数据
非常感谢您!
library(shiny)
library(shinyauthr)
# dataframe that holds usernames, passwords and other user data
user_base <- tibble::tibble(
user = c("a", "user2"),
password = sapply(c("a", "pass2"), sodium::password_store),
permissions = c("admin", "standard"),
name = c("User One", "User Two")
)
ui <- fluidPage(
# logout button
div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
# login section
shinyauthr::loginUI(id = "login"),
# Sidebar to show user info after login
uiOutput("sidebarpanel"),
# Plot to show user info after login
plotOutput("distPlot") ,
dashboardPage(
dashboardHeader(
title = "Title"
),
dashboardSidebar(
tags$div(class = "sidebar-text",style = "text-align: center; font-style: italic;"),
fileInput("csvFile1", "Load file")
),
dashboardBody(
useShinyjs(), # Initialize shinyjs
tags$br(),
actionButton("knitButton", "Generate report"),
downloadButton("downloadReport", "Download report", class = "btn-primary", disabled = TRUE)
) ) )
server <- function(input, output, session) {
credentials <- shinyauthr::loginServer(
id = "login",
data = user_base,
user_col = user,
pwd_col = password,
sodium_hashed = TRUE,
log_out = reactive(logout_init())
)
# Logout to hide
logout_init <- shinyauthr::logoutServer(
id = "logout",
active = reactive(credentials()$user_auth)
)
observeEvent(input$knitButton, {
# Check if two CSV files are uploaded and report options are selected
if (
!is.null(input$csvFile1) ) {
# Show the loading screen
shinyjs::show("loading")
# Disable the knit button during knitting
shinyjs::disable("knitButton")
# Pathway to the RMarkdown code
rmd_path <- "Rmarkdown.Rmd"
knittedFile <- rmarkdown::render(
rmd_path,
output_file = "knitted_report.html",
params = list(
data1 = input$csvFile1$datapath ) )
output$downloadReport <- downloadHandler(
filename = paste0("Report.html") ,
content = function(file) {
file.copy(knittedFile, file)
}
)
# Hide the loading screen
shinyjs::hide("loading")
# Show the "Ready" message
shinyjs::show("ready")
shinyjs::enable("downloadReport")
}
})
}
shinyApp(ui = ui, server = server)
字符串
1条答案
按热度按时间n7taea2i1#
fluidPage()
和dashBoardPage()
都是HTML模板,通过使用这两个,你正在使用HTML模板中的HTML模板,当然,如果你想这样做,你可以这样做。所以没有'这是这个应用程序的正确模板'。这一切都取决于你的喜好,而fluidPage()
是一个几乎'空'的模板,dashBoardPage()
已经定义了一些HTML/CSS元素,如果使用fluidPage()
,则必须自己编写代码。我的意思是
plotOutput("distPlot")
。你看,如果你注解掉这一行,那个空格就消失了。请参见下面的代码示例:
字符串