【发布时间】:2020-06-12 15:15:47
【问题描述】:
我创建了一个闪亮的应用程序,应该从三个滑块中获取输入:
- 在 ggplot 中绘制分布
- 在上面 #1 的图下方显示值的汇总表
如果我只想绘制直方图(并注释掉表格数据),我可以让代码正常工作。但是,当我添加表格时,即使情节标题仍然存在,情节也会消失。我尝试将逗号移动到大括号中,看看它是否是一个简单的语法错误,但没有任何运气。
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Test Shiny Layout"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
h4("Input Data"),
sliderInput("bins", "Bin Width", min = 4,max = 12, value = 8),
),
# Show a plot of the generated distribution
mainPanel(
h4("Histogram"),
plotOutput("distPlot", width = "600", height = "600"),
h4("Table of Values"),
tableOutput("table")
)
)
))
服务器
library(shiny)
library(ggplot2)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
bins <- input$bins
df1 <- (iris$Sepal.Length)
x <- mean(df1)
y <- sd(df1)
ggplot(data = iris) +
geom_histogram(mapping = aes(x = Sepal.Length), color = "blue", binwidth = "bins")
# Create an empty dataframe and then plug in the mean and standard deviation
results <- data.frame("0", "0")
results[1,1] = x
results[1,2] = y
colnames(results) <- c("Mean", "SD")
rownames(results) <- c("Sepal Length")
output$table <- renderTable(results)
})
})
【问题讨论】:
-
我尝试将
renderTable放在下一组大括号之外(所以在图大括号之外),但它没有改变