两个动作按钮中只有一个按钮会以闪亮的方式作出反应。

问题描述 投票:0回答:1

我有一个闪亮的应用程序的例子,如下。我需要有两个 selectInput 控制和每个 selectInput 只有当我点击动作按钮时才会有反应。

我发现的是第一个动作按钮 applyNameFilter 完全没有反应。当悬停在上面时,它没有高亮。第二个操作按钮 applyTimeFilter 似乎还可以。

有人知道为什么吗?太奇怪了... 我不知道怎么解决,在这里寻求帮助。 非常感谢。

library(shinydashboard)
library(shiny)
library(shinyWidgets)
library(shinyjs)
library(dplyr)


df = data.frame(Name = c('A', 'B', 'C', 'A', 'B', 'C'),
       Year = c('2020', '2020', '2020', '2019', '2019', '2019'),
       Value = c(12, 33, 44, 55, 22, 11))

ui <- dashboardPage(
    dashboardHeader(title = "Example" ),
    dashboardSidebar(
        sidebarMenu(
            menuItem("tab", tabName = "tab", icon = icon("globe"))
        ) 
    ), 
    dashboardBody(

        useShinyjs(),

        tabItems(

            tabItem(tabName = "tab",

                    div(id = 'timeAllFilters',
                        box( width=12, background = 'green',

                             selectizeInput(inputId = 'year', 
                                            label='Select Year',
                                          choices = c('', '2020', '2019'),
                                          multiple=FALSE,
                                          options = list(
                                              maxItems = 1,
                                              placeholder = '',
                                              onInitialize = I("function() { this.setValue(''); }"))),

                             actionBttn(
                                 inputId = 'applyTimeFilter',
                                 label = "Apply", 
                                 style = "gradient",
                                 color = "danger",
                                 icon = icon("") ),
                             actionBttn(
                                 inputId = 'clearTimeFilter',
                                 label = "Clear", 
                                 style = "gradient",
                                 color = "danger",
                                 icon = icon("") ) 
                        )  #box
                    ), #div


                    div(id = 'nameAllFilters',
                        dropdown(
                            tags$h3("Filters"),
                            selectizeInput(inputId = 'name', 
                                           label='Select Name',
                                           choices = c('','A', 'B'),
                                           multiple=FALSE,
                                           options = list(
                                               maxItems = 1,
                                               placeholder = '',
                                               onInitialize = I("function() { this.setValue(''); }"))),

                            actionBttn(
                                inputId = 'applyNameFilter',
                                label = "Apply", 
                                style = "gradient",
                                color = "danger",
                                icon = icon("") ),
                            actionBttn(
                                inputId = 'clearNameFilter',
                                label = "Clear", 
                                style = "gradient",
                                color = "danger",
                                icon = icon("") ) 
                        )  #dropdown
                    ), #div

                    dataTableOutput('table')
            ) #tabItem
        ) #tabItems
    ) #dashboardBody
) #dashboardPage


server <- function(input, output, session) {


    df1 = reactive({
        input$applyTimeFilter
        isolate( df %>% filter(Year %in% input$year) )
    })

    # clear time filters 
    observeEvent(input$clearTimeFilter, {
        reset("timeAllFilters")
    })


    df2 = reactive({
        input$applyNameFilter
        isolate ( df1() %>% filter(Name %in% input$name) )
    })

    # clear name filters 
    observeEvent(input$clearNameFilter, {
        reset("nameAllFilters")
    })

    output$table = renderDataTable({
        DT::datatable(df2())
    })
}

shinyApp(ui = ui, server = server)
r shiny shinydashboard
1个回答
1
投票

问题似乎是与 actionBttn 在里面 box(). 它的工作就好了没有。你能不能找到另一种方法来获得同样的风格,而不需要。box()?

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.