r语言 - 闪亮 - 登录后看不到我的 html 页面?



我正在使用 Shiny 并尝试显示我的代码包含一个 csv 文件输入对话框,一个选项卡集,其中包含两个选项卡,可以使用侧面板/主面板或任何其他方式。但是我的代码没有运行包含这些元素的代码。我已成功登录,但不知道如何显示 html 代码并在登录后进行输入。

这是我的代码。

library(shiny)
library(shinyauthr)
library(shinyjs)
library(survival)
library(shinyWidgets)
user_base <- data.frame(
user = c("user1", "user2"),
password = c("pass1", "pass2"), 
permissions = c("admin", "standard"),
name = c("User One", "User Two"),
stringsAsFactors = FALSE,
row.names = NULL
)
ui <- fluidPage(
shinyjs::useShinyjs(),
div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
shinyauthr::loginUI(id = "login"),
setBackgroundColor(color = c("#F7FBFF", "#2171B5"), gradient = "linear", direction = "bottom"),
htmlOutput({
setBackgroundColor(color = c("#000000", "#000000"), gradient = "linear", direction = "bottom")
}),
ui2()
)
ui2<-function()
{
fileInput("file1", "Choose CSV File",
          multiple = FALSE,
          accept = c("text/csv",
                     "text/comma-separated-values,text/plain",
                     ".csv"))
tabsetPanel(type = "tabs",
          tabPanel("Summary of data", tableOutput("maindf")),
          tabPanel("Summary of data", tableOutput("user_table"))
  )
}
server <- function(input, output, session) {
  # call the logout module with reactive trigger to hide/show
  logout_init <- callModule(shinyauthr::logout, 
                        id = "logout", 
                        active = reactive(credentials()$user_auth))
  # call login module supplying data frame, user and password cols
  # and reactive trigger
  credentials <- callModule(shinyauthr::login, 
                        id = "login", 
                        data = user_base,
                        user_col = user,
                        pwd_col = password,
                        log_out = reactive(logout_init()))
  # pulls out the user information returned from login module
  user_data <- reactive({credentials()$info})
  output$user_table <- renderTable({
    # use req to only render results when credentials()$user_auth is TRUE
    req(credentials()$user_auth)
    user_data()
  })
  output$maindf<-renderTable({
  req(input$file1)
  testdb <- read.csv(input$file1$datapath,
                   header = input$header,
                   sep = input$sep,
                   quote = input$quote)
  req(credentials()$user_auth)
  ###### how to show main data frame????
  testdb
  })
}
shinyApp(ui = ui, server = server)

编辑后,我能够满足您的第一个要求:仅在登录后显示 UI,请参阅下面的代码。我在上传 csv 时遇到了问题。你有示例文件吗?

PS:这是一个有趣的 shinyauthr 包工作示例。

library(shiny)
library(shinyauthr)
library(shinyjs)
library(survival)
library(shinyWidgets)
user_base <- data.frame(
  user = c("user1", "user2"),
  password = c("pass1", "pass2"), 
  permissions = c("admin", "standard"),
  name = c("User One", "User Two"),
  stringsAsFactors = FALSE,
  row.names = NULL
)

ui2<-function()
{
  fileInput("file1", "Choose CSV File",
            multiple = FALSE,
            accept = c("text/csv",
                       "text/comma-separated-values,text/plain",
                       ".csv"))
  tabsetPanel(type = "tabs",
              tabPanel("Summary of data", tableOutput("maindf")),
              tabPanel("Summary of data", tableOutput("user_table"))
  )
}
ui <- fluidPage(
  shinyjs::useShinyjs(),
  div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
  shinyauthr::loginUI(id = "login"),
  setBackgroundColor(color = c("#F7FBFF", "#2171B5"), gradient = "linear", direction = "bottom"),
  htmlOutput({
    setBackgroundColor(color = c("#000000", "#000000"), gradient = "linear", direction = "bottom")
  }),
  #ui2(),
  uiOutput("ui2")
)

server <- function(input, output, session) {
  # call the logout module with reactive trigger to hide/show
  logout_init <- callModule(shinyauthr::logout, 
                            id = "logout", 
                            active = reactive(credentials()$user_auth))
  # call login module supplying data frame, user and password cols
  # and reactive trigger
  credentials <- callModule(shinyauthr::login, 
                            id = "login", 
                            data = user_base,
                            user_col = user,
                            pwd_col = password,
                            log_out = reactive(logout_init()))
  # pulls out the user information returned from login module
  user_data <- reactive({credentials()$info})

  output$ui2 <- renderUI({
    req(credentials()$user_auth)
    fluidRow(
      fileInput("file1", "Choose CSV File",
              multiple = FALSE,
              accept = c("text/csv",
                         "text/comma-separated-values,text/plain",
                         ".csv")),
      tabsetPanel(type = "tabs",
                  tabPanel("Summary of data", tableOutput("maindf")),
                  tabPanel("Summary of data", tableOutput("user_table"))
                 )
    )
  })

  output$user_table <- renderTable({
    # use req to only render results when credentials()$user_auth is TRUE
    req(credentials()$user_auth)
    user_data()
  })
  output$maindf<-renderTable({
    req(input$file1)
    testdb <- read.csv(input$file1$datapath,
                       header = input$header,
                       sep = input$sep,
                       quote = input$quote)
    req(credentials()$user_auth)
    ###### how to show main data frame????
    testdb
  })
}
shinyApp(ui = ui, server = server)

最新更新