【问题标题】:How to add floating button in shinydashboard如何在闪亮仪表板中添加浮动按钮
【发布时间】:2018-08-15 14:15:05
【问题描述】:

我正在做一些需要在闪亮仪表板中使用浮动按钮的事情。下面是使用 shinyMaterial 包获取浮动按钮的代码。

library(shiny)
library(shinymaterial)

# Wrap shinymaterial apps in material_page
ui <- material_page(title = "Basic Page",
      tags$h1("Page Content"),

      material_floating_button(
        input_id = "example_floating_button",
        icon = "live_help",
        depth = 5,
        color = "red lighten-3"
      )
    )

    server <- function(input, output) {

    }
    shinyApp(ui = ui, server = server)

当我尝试在 shinydashboard 中使用来自 shinymaterial 库的浮动按钮时,它不起作用。任何帮助表示赞赏,如果每个页面上都有一个浮动按钮..使用任何库,我想要的只是。

library(shiny)
library(shinydashboard)
library(dplyr)
library("shinymaterial")

ui <- dashboardPage(
          dashboardHeader(dropdownMenuOutput("notificationMenu")),
                              dashboardSidebar(sidebarMenu(menuItem("Page 1", tabName = "page1"),
                                                 menuItem("Page 2", tabName = "page2"))),
          dashboardBody(tabItems(
            tabItem(tabName = "page1", h4("This is Page 1"),
                    material_floating_button(
                                input_id = "example_floating_button",
                                icon = "live_help",
                                depth = 5,
                                color = "red lighten-3"
                              )),
            tabItem(tabName = "page2", 
                              textInput("text", "Enter News:", "New News."),
                              actionButton("save", "Save"))
            )))

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

  # Intial Header News: 1 Message from Admin
  raw_news$news <- data_frame(from = "Admin", text = "this is a message")

  # The notifications in header
  output$notificationMenu <- renderMenu({
    raw_news <- raw_news$news

    dropdownMenu(
      messageItem(raw_news$from[1], raw_news$text[1])
      )
  })

  # save a new notification
  observeEvent(input$save, {
    raw_news$news <- data.frame(from = "User", text = input$text)
  }) 
}

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny floating-action-button shinydashboard shinyjs


    【解决方案1】:

    只需在 fixedPanel 中使用 actionButton

    tabItem(tabName = "page1", h4("This is Page 1"),
    
            fixedPanel(
              actionButton("test", label = "test"),
              right = 10,
              bottom = 10
            )
    ),
    

    【讨论】:

    • @kawsleo 非常欢迎您,如果您觉得有用,请接受答案。
    • 完成!!再次感谢!!
    猜你喜欢
    • 2018-08-02
    • 2020-01-22
    • 2015-12-12
    • 2018-02-24
    • 2019-04-19
    • 2020-08-31
    • 2021-04-09
    • 2015-04-22
    • 2022-01-04
    相关资源
    最近更新 更多