R闪亮的仪表板主体取决于闪亮的子项选择

时间:2018-09-18 09:02:56

标签: r events shiny submenu action-button

这是一种根据闪亮的子项选择创建闪亮的watchEvent的方法吗?

在下面的可复制示例中,我想在单击子菜单1时自动执行按钮1,而在单击子菜单2时自动执行按钮3。

library(shinydashboard)
library(shiny)


ui <- dashboardPage(
 dashboardHeader(title = "Dynamic sidebar"),
 dashboardSidebar(
   sidebarMenuOutput("menu")
 ),
dashboardBody(heigth = 800,  tabItems(
                                     tabItem(tabName = "submenu_1",
                                             fluidRow(
                                               actionButton(inputId = "button_1",label = "Button 1",  icon = icon("fa"),width = '417px'),
                                               actionButton(inputId = "button_2",label = "Button 2",  icon = icon("fa"),width = '417px')
                                             )
                                     ),
                                       tabItem(tabName = "submenu_2",
                                               fluidRow(
                                                 actionButton(inputId = "button_3",label = "Button 3",  icon = icon("fa"),width = '417px'),
                                                 actionButton(inputId = "button_4",label = "Button 4",  icon = icon("fa"),width = '417px')
                                               )
                                       )

                        ),
            textOutput("text")
            )
)


server <- function(input, output) {
output$menu <- renderMenu({
sidebarMenu(
  menuItem("Menu item 1", 
           menuSubItem('Submenu 1',tabName = 'submenu_1',icon = icon('line-chart')),
           menuSubItem('Submenu 2',tabName = 'submenu_2',icon = icon('line-chart'))
           )
)
})


 observeEvent(input$button_1,{output$text <- renderText("Buutton 1 must be selected by default on Submenu 1")})
 observeEvent(input$button_2,{output$text <- renderText("You have selected button 2")})
 observeEvent(input$button_3,{output$text <- renderText("Buutton 3 must be selected by default on Submenu 2 ")})
 observeEvent(input$button_4,{output$text <- renderText("You have selected button 4")})
}

shinyApp(ui, server)

提前谢谢!

2 个答案:

答案 0 :(得分:2)

是您需要的吗?

您可以在Status: 404 Not Found X-Powered-By: PHP/7.1.20 Content-type: text/html; charset=UTF-8 No input file specified. 中添加一个class PostPublish extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'post:publish {id}'; /** * The console command description. * * @var string */ protected $description = 'Publish posts that have been scheduled'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $post = BlogPost::find($this->argument('id')); $post->status = "published"; $post->published_at = $post->scheduled_at; $post->scheduled_at = null; return $post->save(); } } 参数,然后添加一个由class Kernel extends ConsoleKernel { /** * The Artisan commands provided by your application. * * @var array */ protected $commands = [ // ]; /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $tasks = Task::all(); foreach ($tasks as $task) { $schedule->command($task->command) ->cron($task->cron) ->appendOutputTo('/home/qs266dg7/public_html/storage/app/Console/cron.log'); } } /** * Register the commands for the application. * * @return void */ protected function commands() { $this->load(__DIR__.'/Commands'); require base_path('routes/console.php'); } } 触发的id对象

sidebarMenu

答案 1 :(得分:1)

诀窍是在用户界面部分设置参数id

下面的代码可以完成工作:

library(shinydashboard)
library(shiny)


ui <- dashboardPage(
    dashboardHeader(title = "Dynamic sidebar"),
    dashboardSidebar(
        sidebarMenu(id="tabs",
            sidebarMenuOutput("menu")
        )
    ),
    dashboardBody(heigth = 800,  tabItems(
        tabItem(tabName = "submenu_1",
                fluidRow(
                    actionButton(inputId = "button_1",label = "Button 1",  icon = icon("fa"),width = '417px'),
                    actionButton(inputId = "button_2",label = "Button 2",  icon = icon("fa"),width = '417px')
                )
        ),
        tabItem(tabName = "submenu_2",
                fluidRow(
                    actionButton(inputId = "button_3",label = "Button 3",  icon = icon("fa"),width = '417px'),
                    actionButton(inputId = "button_4",label = "Button 4",  icon = icon("fa"),width = '417px')
                )
        )

    ),
    textOutput("text")
    )
)


server <- function(input, output) {
    output$menu <- renderMenu({
        sidebarMenu(
            menuItem("Menu item 1", 
                     menuSubItem('Submenu 1',tabName = 'submenu_1',icon = icon('line-chart')),
                     menuSubItem('Submenu 2',tabName = 'submenu_2',icon = icon('line-chart'))
            )
        )
    })

    observeEvent(input$tabs, {
        req(input$tabs)
        if (input$tabs == "submenu_1") {
            # Do whatever you want when submenu_1 is selected
            print("submenu_1 selected")
        } else if (input$tabs == "submenu_2") {
            # Do whatever you want when submenu_2 is selected 
            print("submenu_2 selected")
        }
    })
    observeEvent(input$button_1,{output$text <- renderText("Buutton 1 must be selected by default on Submenu 1")})
    observeEvent(input$button_2,{output$text <- renderText("You have selected button 2")})
    observeEvent(input$button_3,{output$text <- renderText("Buutton 3 must be selected by default on Submenu 2 ")})
    observeEvent(input$button_4,{output$text <- renderText("You have selected button 4")})
}

shinyApp(ui, server)