I am working on shinydashboard box feature. I want to achieve following points.
-
On rendering output table the input box should be collapsed. Is there any way I can achieve this ?
-
When I want to print table from "Second Box" after "First Box" eventReactive of second submit button is not responding. What needs to be done in order to fix this ?
-
Progress Bar is shown on loading of page but it should be shown only on rendering output table. How to fix this ?
ui.R
library(shiny)
library(shinyjs)
library(shinydashboard)
library(DT)
shinyUI(
dashboardPage(title = "My Page",
dashboardHeader(
title = "My Header",
titleWidth = 200
),
dashboardSidebar(
width = 200,
sidebarMenu(
menuItem("My Data", selected = FALSE,
menuSubItem(text = "My Data", tabName = "my_data", newtab = TRUE, selected = FALSE)
)
)
),
dashboardBody(
useShinyjs(),
tabItems(
# First tab content
tabItem(tabName = "my_data",
h2("Please select fields"),
div(
fluidRow
(
box(title = 'First Box', background = 'green', collapsible = TRUE, collapsed = TRUE,
column(2,
actionButton("sub_mt", "Show MT Cars")
)),
box(title = 'Second Box', background = 'yellow', collapsible = TRUE, collapsed = TRUE,
column(2,
actionButton("sub_iris","Show Iris Data")
))
)
)
)
),
DT::dataTableOutput('optable'),
textOutput('message')
)
))
server.R
library(shiny)
library(shinydashboard)
library(DT)
library(shinyjs)
if (interactive()) {
shinyServer(function(session,input,output){
dt_mtcars <- eventReactive(input$sub_mt,
{
mtcars
})
dt_iris <- eventReactive(input$sub_iris,
{
iris
})
output$optable <- DT::renderDataTable({
withProgress(message = 'Data Loading...',value = 0, {
for (i in 1:15) {
incProgress(1/15)
Sys.sleep(0.25)
}
})
if(input$sub_mt == TRUE)
{
dt_tab=dt_mtcars()
} else{
dt_tab=dt_iris()
}
datatable(dt_tab, rownames = FALSE, filter = 'top',
style = 'bootstrap', selection = 'single')}
)
}
)
}