#r #shiny #shinydashboard #shinydashboardplus
Вопрос:
У меня есть блестящее приложение ниже с 3 различными вкладками, боковой панелью и правой боковой панелью. Я хотел бы, чтобы каждый раз, когда я перемещаюсь на другую вкладку, содержимое правой боковой панели менялось и отображало разные виджеты. В третьем, хотя и названном «Сбор налоговых убытков», я хочу добавить а controlbarMenu()
. Как я могу сделать так, чтобы он отображался только тогда, когда я на третьей вкладке?
library(shiny) library(shinydashboard) library(shinydashboardPlus) shinyApp( ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage( options = list(sidebarExpandOnHover = TRUE), header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450), sidebar = dashboardSidebar(minified = F, collapsed = F, h4("Investment Selected") ), body = dashboardBody( h3('Results'), tabsetPanel(id = "tabs", tabPanel("InsiderTraining"), tabPanel("Switching"), tabPanel("Tax Loss Harvesting") ) ), controlbar = dashboardControlbar(width = 300, #controlbarMenu( # id = "menu", #controlbarItem( # "Tab 1", #"Welcome to tab 1" #), #controlbarItem( # "Tab 2", #"Welcome to tab 2" #) #) h4("Insider Trading Parameters"), uiOutput("mytab21"), uiOutput("mytab22"),uiOutput("mytab23") ), title = "DashboardPage" )), server = function(input, output) { output$mytab21 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="InsiderTraining"', selectInput("InsiderTradingModel", "Insider Trading Model", c("Dynamic" = "Dynamic", "AI based" = "AIbased")), #textInput("StockTicker", "Enter Stock Symbol", value = "NFLX"), selectInput("ivar", "Choose a variable", choices = colnames(iris)) )) }) output$mytab22 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="Switching"', selectInput("InsiderTradingModel2", "Insider Trading Model 2", c("Dynamic" = "Dynamic", "BI based" = "BIbased")), sliderInput('periodss','Periods',min=1,max=100,value=30), selectInput("pvar", "Choose a variable", choices = colnames(pressure)) )) }) output$mytab23 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="Switching"', )) }) } )
Ответ №1:
Возможно, вы ищете это
menu lt;- controlbarMenu( id = "controlbarMenu", controlbarItem( "Tab 1", "Welcome to tab 1" ), controlbarItem( "Tab 2", numericInput("num", "Observations:", 200, min = 1, max = 1000, step = 100) ) ) library(shiny) library(shinydashboard) library(shinydashboardPlus) shinyApp( ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage( options = list(sidebarExpandOnHover = TRUE), header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450), sidebar = dashboardSidebar(minified = F, collapsed = F, h4("Investment Selected"), uiOutput("mytab11"), uiOutput("mytab12") #textInput("StockTicker3", "Enter Stock Symbol 3", value = "AMZN") ), body = dashboardBody( h3('Results'), tabsetPanel(id = "tabs", tabPanel("InsiderTraining"), tabPanel("Switching"), tabPanel("Tax Loss Harvesting") ) ), controlbar = dashboardControlbar(width = 300, h4("Insider Trading Parameters"), uiOutput("mytab21"), uiOutput("mytab22"), uiOutput("mytab32") #selectInput("InsiderTradingModel3", "Insider Trading Model 3", # c("Dynamic" = "Dynamic", # "AI based" = "AIbased")) ), title = "DashboardPage" )), server = function(input, output) { output$mytab11 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="InsiderTraining"', textInput("StockTicker", "Enter Stock Symbol", value = "NFLX"), sliderInput('periods','Periods',min=1,max=120,value=60), selectInput("mtvar", "Choose a variable", choices = colnames(mtcars)) )) }) output$mytab12 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="Switching"', textInput("StockTicker2", "Enter Stock Symbol", value = "APPL"), selectInput("cvar", "Choose a variable", choices = colnames(cars)) )) }) output$mytab21 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="InsiderTraining"', selectInput("InsiderTradingModel", "Insider Trading Model", c("Dynamic" = "Dynamic", "AI based" = "AIbased")), #textInput("StockTicker", "Enter Stock Symbol", value = "NFLX"), selectInput("ivar", "Choose a variable", choices = colnames(iris)) )) }) output$mytab22 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="Switching"', selectInput("InsiderTradingModel2", "Insider Trading Model 2", c("Dynamic" = "Dynamic", "BI based" = "BIbased")), sliderInput('periodss','Periods',min=1,max=100,value=30), selectInput("pvar", "Choose a variable", choices = colnames(pressure)) )) }) output$mytab32 lt;- renderUI({ tagList( conditionalPanel(condition = 'input.tabs=="Tax Loss Harvesting"', selectInput("pvar", "Choose a variable", choices = colnames(rock)), menu )) }) } )
Комментарии:
1. вкладки 1 и 2 должны отображаться только в 3-й панели вкладок «Сбор налоговых убытков».
2. @firmo23, пожалуйста, попробуйте обновленный код.
3. У меня тот же вопрос: вы нашли решение?