r - 当闪亮的应用程序第一次启动时显示一个按钮,这将导致 tabItems 内容
问题描述
我有shiny
下面的应用程序,其中包括 tabItems。我希望在第一次启动应用程序时显示actionbutton
tabItems 内容之外的内容。然后当我按下它时,我将被移动到Consent
tabItem。该按钮从那里以后将不再有用,并且它应该消失,因为将显示 tabItems 的内容。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
mytitle <- paste0("")
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(
div(style="display: inline;margin-top:-35px; padding: 0px 90px 0px 1250px ;font-size: 44px ;color:#001641;font-family:Chronicle Display Light; width: 500px;",HTML(mytitle)),
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("conse", "Consent",
style=" background-color: #faf0e6; border-color: #faf0e6")),
),
class = "dropdown")
)
shinyApp(
ui = dashboardPagePlus(
header = dbHeader,
sidebar = dashboardSidebar(width = "0px",
sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Consent", tabName = "conse", icon = icon("line-chart"))
) ),
body = dashboardBody(
tags$head(tags$style(HTML('
'))),
useShinyjs(),
tags$script(HTML("$('body').addClass('fixed');")),
tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
actionButton("button", "Get started",style='padding:4px; font-size:140%'),
tabItems(
tabItem("conse",
textInput("pos", label = ("Position"), value = "")
)
)
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
observeEvent(input$button, {
updateTabItems(session, "sidebar",
selected = "conse")
})
}
)
)
解决方案
也许你正在寻找这个
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
mytitle <- paste0("")
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(
div(style="display: inline;margin-top:-35px; padding: 0px 90px 0px 1250px ;font-size: 44px ;color:#001641;font-family:Chronicle Display Light; width: 500px;",HTML(mytitle)),
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("conse", "Consent",
style=" background-color: #faf0e6; border-color: #faf0e6") ),
), class = "dropdown")
)
shinyApp(
ui = dashboardPagePlus(
header = dbHeader,
sidebar = dashboardSidebar(width = "0px",
sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Consent", tabName = "conse", icon = icon("line-chart"))
) ),
body = dashboardBody(
tags$head(tags$style(HTML('
'))),
useShinyjs(),
tags$script(HTML("$('body').addClass('fixed');")),
tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
actionButton("button", "Get started",style='padding:4px; font-size:140%'),
tabItems(
tabItem("conse", textInput("pos", label = ("Position"), value = "") )
)
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
shinyjs::hide("conse")
shinyjs::hide("pos")
observeEvent(input$button, {
shinyjs::show("conse")
shinyjs::show("pos")
updateTabItems(session, "sidebar",
selected = "conse")
shinyjs::hide("button")
})
}
)
)
推荐阅读
- javascript - 停止在 Material UI 中同时更改图标
- python - 如何在 Python 中使用 networkx 读取 GraphML 文件?
- database - OTLT(一个真正的查找表)曾经是一个好方法吗?
- python - Orange3 和 Python 数据导出/导入
- java - 使用 Hibernate Search 查询并获取所有项目而无需分页
- javascript - JS 在 ToneJS 中切换文本和状态
- python - 如何在文件中搜索和替换字符串
- java - 如何在 Android Studio 中跨活动保存变量值
- swift - 我正在尝试从 swift 的 api 休息调用中取回一个数组
- java - 如何将数组从一个类转移到另一个类?