【发布时间】:2021-01-05 05:50:35
【问题描述】:
我有下面的shiny 应用程序。当应用程序第一次启动时,它会在主体中显示一个操作按钮 Get Started,在标题中显示 3 个操作按钮。
- 用户可以按他之前希望的这 3 个标题按钮中的任何一个
按下
Get Started按钮。没关系,他再也看不到Get Started按钮了
如果他按下Consent,他将被移动到Consent tabItem。然后他可以写一个名字按Run Project 并在Results tabItem 中查看情节。
如果他在Consent 输入姓名之前按Run Project,他将自动移入Consent 以便输入姓名。
如果他在输入姓名之前按ResultsConsent,他将自动进入同意以输入姓名。
- 用户首先按下
Get Started按钮,然后移动到Consent选项卡以键入名称,然后Run Project移动到 结果。
我认为由于Run Project 和Get Started 两个动作按钮的冲突,我的代码deos 无法正常工作。
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") ),
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("rp", "Run Project",
style=" background-color: #faf0e6; border-color: #faf0e6") ),
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("res", "Results",
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")),
menuItem("Results", tabName = "res", icon = icon("line-chart"))
)
),
body = dashboardBody(
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",
conditionalPanel(condition = "input.conse >0 || input.button>0",
textInput("nam", label = ("Name"), value = "")
)
),
tabItem("res", uiOutput('markdown')
)
)
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
observeEvent(input$button, {
updateTabItems(session, "sidebar", selected = "conse")
shinyjs::hide("button")
})
observeEvent(input$conse, {
updateTabItems(session, "sidebar", selected = "conse")
shinyjs::hide("button")
})
observeEvent(input$button, {
if (input$nam=="") {
updateTabItems(session, "sidebar",
selected = "conse")
}
else{
updateTabItems(session, "sidebar",
selected = "res")
}
})
observeEvent(input$rp, {
if (input$nam=="") {
updateTabItems(session, "sidebar",
selected = "conse")
}
else{
updateTabItems(session, "sidebar",
selected = "res")
}
})
output$markdown <- renderUI({input$rp
if (input$nam==""){
return(NULL)
}
else{
isolate(plot(iris))
}
})
}
)
)
【问题讨论】: