【问题标题】:R: Shiny: How to align a gvisTable to the center in shinyappR:闪亮:如何在闪亮应用中将 gvisTable 与中心对齐
【发布时间】:2015-03-04 02:04:17
【问题描述】:

在 Google 上的闪亮组中寻找:

https://groups.google.com/forum/#!topic/shiny-discuss/J8C2CnFOTOM

我找到了一个解决方案,但是我只知道 HTML 的基础知识和一点 CSS。如何在我的代码中实现解决方案?

我需要将 gvisTable 放在中心。我把代码直接放到 htmlOutput 函数中,作为参数却报错:

**注意:这是我对代码所做的唯一更改。

 tabPanel('Ikasa Adwords MotionChart',
                   br(),
                   htmlOutput("resumen",
                              tags$style(type="text/css",
                                         HTML("#summary>div { margin: 0 auto; }")
                              )),
                   br(),
                   br(),

错误:

ERROR: argument is not interpretable as logical

原始ui.R:

library(shiny)
library(googleVis)
# Rely on the 'WorldPhones' dataset in the datasets
# package (which generally comes preloaded).


# Define the overall UI
shinyUI(

  # Use a fluid Bootstrap layout
  fluidPage(    

    # Give the page a title
    br(),
    br(),
    br(),
    titlePanel("Ikasa Adwords"),

    # Generate a row with a sidebar
    br(),
    br(),
    sidebarLayout(      

      # Define the sidebar with one input



      sidebarPanel(
        dateRangeInput("dates", label = h3("Date range"),
                       start = "2015-01-01", end = "2015-02-15")

      ),



      mainPanel(
        tabsetPanel(

          tabPanel('Ika MotionChart',
                   br(),
                   htmlOutput("resumen",
                              tags$style(type="text/css",
                                         HTML("#summary>div { margin: 0 auto; }")
                              )),
                   br(),
                   br(),

                   htmlOutput("motionchart")

        )

      )
    )
  )))

【问题讨论】:

  • 猜猜htmlOutput 在这种情况下tags$style 不接受第二个参数作为标签。您可以只提及内联真或假。同样在您的样式标签中,您说的是#summary,并且您的代码中没有ID为#summary的div。为了使其居中,您需要为元素提供宽度以及margin: 0 auto

标签: css r shiny


【解决方案1】:

您可以尝试直接在桌子上设置css,使用tag$style

例如:

tabPanel('Ika MotionChart',
                   br(),
                   htmlOutput("resumen"),
                   tags$style(HTML("#resumen table{ 
                                  margin: auto;
                                   }")),
                   br(),
                   br(),

                   htmlOutput("motionchart")
                   tags$script(HTML("
                        var p = document.getElementById('motionchart')
                        $(p).attr('align', 'center');"))

          ) 

css 将具有resumen id 的元素中的所有table 的左右边距设置为autotable 周围的左右边距应平均分割,从而形成居中的表格。

对于motionChart,实际图表是embed 元素,因此您可以通过使用javascript 设置align 属性来更改对齐方式。

在 chrome 中,我得到了一些 WorldPhone 数据:

【讨论】:

  • 它有效。请您添加一个动态图表的示例。根据此页面中的信息:[链接]developers.google.com/chart/interactive/docs/gallery/… ...我做了这个代码:tags$style(HTML("#motionchart motionchart{ margin-left: auto; margin-right: auto; }") ), htmlOutput("motionchart") 但它不起作用。
猜你喜欢
  • 2017-01-12
  • 2018-02-18
  • 2015-04-29
  • 2014-06-30
  • 2015-04-26
  • 1970-01-01
  • 1970-01-01
  • 2021-08-16
  • 2017-08-12
相关资源
最近更新 更多