I am using Shiny and trying to display my code contains a csv file input dialog a tabset with two tabs either using sidepanel/mainpanel or any other way. But my code is not running the code containing these elements. I am successfully able to login but do not know how to show the html code and take input after login.
Here is my code.
library(shiny)
library(shinyauthr)
library(shinyjs)
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)