【问题标题】:change appearance of text outputs in shiny app with tab panels使用选项卡面板更改闪亮应用程序中文本输出的外观
【发布时间】:2018-07-24 07:10:14
【问题描述】:

我正在制作一个带有多个面板和选项卡的 Shiny 应用程序。这是我的 UI 的迷你版:

shinyUI(pageWithSidebar(
headerPanel("TrackAware Data Summary"),

sidebarPanel(
fileInput('file1', 'Choose CSV File',
          accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
width = 2,
selectInput("graph", "Choose a graph to view:", 
            choices = c("Best Times to Depart",
                        "Fastest Hour vs. Slowest Hour",
                        "Average Delivery Times per Driver",
                        "Fastest Driver vs. Slowest Driver",
                        "Deliveries per Driver", 
                        "Deliveries per Day", 
                        "Drivers per Day", 
                        "Daily Average Delivery Times",
                        "Driver Consistency"
            )),
submitButton("Update View")
),#end of sidebar panel

mainPanel(
width = 10,
tabsetPanel(
  tabPanel("Dashboard", textOutput("text1"), textOutput("text2")),
  tabPanel("Graph Switcher", plotOutput("selected_graph"))
)
))
)

在服务器端,我有创建文本输出 text1 和 text2 的代码:

output$text1 <- renderText({
"this is text1"
})

output$text2 <- renderText({
"this is text2"
})

是否可以在字体样式、字体大小、颜色、下划线方面更改 text1 和 text2 的外观?我尝试在 "width = 10" 行和 "textOutput("text2")" 行之后插入 css,但它没有改变任何东西。

tags$head(tags$style("#text1{color: red;
                             font-size: 20px;
                             font-style: italic;
                             }"
                     )
          )

),

感谢任何帮助。

【问题讨论】:

    标签: css r shiny


    【解决方案1】:

    以下代码对我来说很好,但我不确定为什么它不适合你。下面的代码对你有用吗?您是否以类似的方式插入标签?

    ui<- shinyUI(pageWithSidebar(
      headerPanel("TrackAware Data Summary"),
    
      sidebarPanel(
        tags$head(tags$style("#text1{color: red;
                                 font-size: 20px;
                             font-style: italic;
                             }"
                         )
        ),
        tags$head(tags$style("#text2{color: blue;
                                 font-size: 20px;
                             font-style: italic;
                             }"
        )
        ),
        fileInput('file1', 'Choose CSV File',
                  accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),
        tags$hr(),
        checkboxInput('header', 'Header', TRUE),
        width = 2,
        selectInput("graph", "Choose a graph to view:", 
                    choices = c("Best Times to Depart",
                                "Fastest Hour vs. Slowest Hour",
                                "Average Delivery Times per Driver",
                                "Fastest Driver vs. Slowest Driver",
                                "Deliveries per Driver", 
                                "Deliveries per Day", 
                                "Drivers per Day", 
                                "Daily Average Delivery Times",
                                "Driver Consistency"
                    )),
        submitButton("Update View")
      ),#end of sidebar panel
    
      mainPanel(
        width = 10,
        tabsetPanel(
          tabPanel("Dashboard", textOutput("text1"), textOutput("text2")),
          tabPanel("Graph Switcher", plotOutput("selected_graph"))
        )
      ))
    )
    
    server <- function(input,output)
    {
      output$text1 <- renderText({
        "this is text1"
      })
    
      output$text2 <- renderText({
        "this is text2"
      })
    }
    
    shinyApp(ui,server)
    

    【讨论】:

    • 非常感谢弗洛里安!由于在这里对 SO 进行了研究,我有正确的代码,但我不知道在哪里将它添加到我现有的代码中。我尝试了您的解决方案,它完美地再现了您的屏幕截图。
    猜你喜欢
    • 2016-03-22
    • 2023-03-20
    • 1970-01-01
    • 2015-09-30
    • 2020-07-22
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多