使用选项卡面板更改闪亮应用程序中文本输出的外观

时间:2018-02-13 20:12:53

标签: css r 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的外观?我尝试在行&#34; width = 10&#34;之后插入css。然后&#34; textOutput(&#34; text2&#34;)&#34;但它没有改变任何东西。

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

),

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

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

enter image description here

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)