我试图将我的所有过滤器容纳在一个模态中(出于外观目的),但它没有达到我的期望。
下面是一个示例代码,用于比较两种方法(侧边栏中的常规过滤器和模式中的过滤器)。玩模态,看看:
rm(list=ls())
library(shiny)
library (shinydashboard)
header <- dashboardHeader(title = "Test")
sidebar <- dashboardSidebar(
sliderInput(inputId = "bins1",
label = "Number of bins:",
min = 1,
max = 50,
value = 30),
actionButton("filterBT", "Filters")
)
body <- dashboardBody(
fluidRow(
box(
title = "Graph using sidebar filter", status = "primary", solidHeader = TRUE, width = 6,
plotOutput("distPlot1")
),
box(
title = "Graph using button filter", status = "primary", solidHeader = TRUE, width = 6,
plotOutput("distPlot2")
)
)
)
ui <- dashboardPage(header, sidebar, body)
#######################################/SERVER/####################################
server <- function(input, output, session) {
myModal <- function() {
div(id = "test",
modalDialog(uiOutput("Network"),
br(),
br(),
easyClose = TRUE, title = "Filter Selections")
)
}
# open modal on button click
observeEvent(input$filterBT,
ignoreNULL = TRUE, # Show modal on start up
showModal(myModal())
)
output$Network <- renderUI ({
sliderInput(inputId = "bins2",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
})
output$distPlot1 <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins1 + 1)
hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
output$distPlot2 <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins2 + 1)
hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
}
shinyApp(ui, server)