Hello !
I am learning Shiny to develop an app.
I want to see the second tabitem contents (which is table from uploaded file) after I click on Submit button.
I ran the below code but it is not working, even after click on actionbutton, it is still showing me the first tabitem contents or it is not changing !
Thanks
My Code:
# Upload library ----
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Simple tabs"),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem("About", tabName = "first",icon = icon("home")),
menuItem("Upload Data", tabName = "second", icon = icon("home"),
fileInput("file1", "Upload a .txt file ",
accept = c("text/csv", "text/comma-separated-values,text/plain",".csv",
options(shiny.maxRequestSize=900*1024^2))),
actionButton('subm', 'Submit'))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "first",
h3("App Ver 0.1.0")
),
tabItem(tabName = "second",
h2("Results Table"),
tableOutput("contents")
)
)
)
)
server <- function(input, output, session) {
observeEvent(input$subm, {
output$contents <- renderTable(rownames = TRUE,{
if (is.null(input$file1)) return(NULL)
head(read.csv(input$file1$datapath))
})
updateTabItems(session, "tabs", selected = "second" )
})
}
shinyApp(ui, server)