【问题标题】:How to make a shiny app full screen automatically?如何使闪亮的应用程序自动全屏?
【发布时间】:2021-10-09 12:31:37
【问题描述】:

我正在使用shinymanager 登录一个闪亮的应用程序。感谢this 问题,我可以通过在我闪亮的应用程序上添加一个操作按钮来使页面全屏显示。但是,我希望应用程序在登录后自动全屏显示。

我尝试使用observeEvent() wrt 进行用户身份验证,如下所示;

auth  <- secure_server( check_credentials = check_credentials(".\\cr\\db.sqlite"))
creds_reactive <- reactive({  auth$user  })

observeEvent(  auth$user, {

        source(".\\funcs\\myfun.R", local = TRUE)  # this works

        js$toggleFullScreen()  # not working

  })

我可以通过在observeEvent() 中使用auth$user 来触发源函数,但是全屏功能不起作用。

但是,我可以通过单击下面的按钮在服务器端触发完全相同的功能。

# Server side
     onclick("my_full_screen_button", {
          js$toggleFullScreen()  # this works
    
        })

# Ui side
 tags$li(id="tam",class = "dropdown", 
    actionButton(icon = icon("expand-arrows-alt"), 'my_full_screen_button','',style="color: #fff; background-color: #888888; border-color: #888888") ),

    

我怀疑它源于jsToggleFS。但是我对JS几乎一无所知。

提前谢谢你。

【问题讨论】:

    标签: r shiny shinyjs


    【解决方案1】:

    我会尝试这样的事情

    library(shiny)
    library(shinyjs)
    
    js <- "
    function openFullscreen(elem) {
      if (elem.requestFullscreen) {
        elem.requestFullscreen();
      } else if (elem.mozRequestFullScreen) { /* Firefox */
        elem.mozRequestFullScreen();
      } else if (elem.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
        elem.webkitRequestFullscreen();
      } else if (elem.msRequestFullscreen) { /* IE/Edge */
        elem.msRequestFullscreen();
      }
    }"
    
    ui <- fluidPage(
      tags$head(
        tags$script(HTML(js))
      ),
      useShinyjs(),
      ......
    

    server:

    observeEvent(auth$user, {
    
      source(".\\funcs\\myfun.R", local = TRUE)  
    
      runjs("openFullscreen(document.documentElement)")
    
    })
    

    【讨论】:

    • 它没有用。顺便说一句,我使用的是shinydashboard。所以也许我无法将 ui 端放在正确的位置。对此有何建议? (在dashboardBody下?还是?)
    • @maydin 是的,在dashboardBody。还可以尝试将runjs 放在source 之前。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-09
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 2018-05-12
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多