【发布时间】:2018-06-09 16:23:50
【问题描述】:
我有以下闪亮的应用程序
ui.R
data("iris")
library(ggplot2)
library(dplyr)
ui <- fluidPage(theme = "mystyle.css",
tabsetPanel(
tabPanel("Tab 1", "Hello"),
div(id = "box1", style="color:#0000FF", selectInput("boxplot1", "Choose a dataset:",
choices = c(list("setosa", "versicolor", "virginica")))),
div(id = "box2", selectInput("boxplot1", "Choose a dataset:",
choices = c(list("setosa", "versicolor", "virginica"))))
),
mainPanel(plotOutput("plot_boxplot"))
)
服务器.R
library(shiny)
library(datasets)
shinyServer(function(input, output) {
filtered <- reactive({
iris %>%
filter(Sepal.Length >= 0)
})
output$plot_boxplot <- renderPlot({
ggplot(filtered(), aes(x=Species, y=Sepal.Length)) +
geom_point(size = 4) +
geom_boxplot() +
ylab("Sepal Length") +
stat_summary(fun.y=mean, geom="point", shape=5, size=4)
})
# Generate a summary of the dataset
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})
这一切都很好。不过我想包含一些自定义 CSS。
如果我使用我的第一个输入框,请将其包装成一个 div 语句并包含一些像这样的 .css:
div(id = "box1", style="color:#0000FF", selectInput("boxplot1", "Choose a dataset:",
choices = c(list("setosa", "versicolor", "virginica")))),
它有效。但是,出于组织目的,我想将其存储为单独的 .css 文件。如果我在我的 www 文件夹中创建并包含一个链接:
ui <- fluidPage(theme = "mystyle.css",
并将以下内容添加到文件 mystyle.css:
#box1{
width: 20%;
height: 100px;
style="color:#0000FF";
}
我没有得到相同的结果。检查这里的所有代码:
mystyle.css
#box1{
width: 20%;
height: 100px;
style="color:#0000FF";
}
ui.R
data("iris")
library(ggplot2)
library(dplyr)
ui <- fluidPage(theme = "mystyle.css",
tabsetPanel(
tabPanel("Tab 1", "Hello"),
div(id = "box1", selectInput("boxplot1", "Choose a dataset:",
choices = c(list("setosa", "versicolor", "virginica")))),
div(id = "box2", selectInput("boxplot1", "Choose a dataset:",
choices = c(list("setosa", "versicolor", "virginica"))))
),
mainPanel(plotOutput("plot_boxplot"))
)
服务器.R
library(shiny)
library(datasets)
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
filtered <- reactive({
iris %>%
filter(Sepal.Length >= 0)
})
output$plot_boxplot <- renderPlot({
ggplot(filtered(), aes(x=Species, y=Sepal.Length)) +
geom_point(size = 4) +
geom_boxplot() +
ylab("Sepal Length") +
stat_summary(fun.y=mean, geom="point", shape=5, size=4)
})
# Generate a summary of the dataset
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})
对我在这里做错了什么有什么想法吗?
【问题讨论】: