【发布时间】:2019-11-01 00:25:32
【问题描述】:
我正在尝试创建一个闪亮的应用程序,让用户
通过输入不同值的频率计数来创建数据集
绘制该数据集的直方图
一个配对返回的代码示例如下:
library(shiny)
library(ggplot2)
# Define UI for application
ui <- fluidPage(
# Sidebar with inputs
sidebarLayout(
sidebarPanel(
numericInput("data1s",
"How many have a score of 1?",
value = 0,
min = 0
),
numericInput("data2s",
"How many have a score of 2?",
value = 0,
min = 0
),
sliderInput("bins",
"Number of bins:",
min = 1,
max = 3,
value = 1)
),
# Show a plot of the data
mainPanel(
htmlOutput("mydatatable"),
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#show the data
output$mydatatable <- renderTable({
#create the dataframe from the frequncies
mydata <- data.frame(our_data=c(rep(1,input$data1s),rep(2,input$data2s))
)
}
)
#show the histogram
output$distPlot <- renderPlot({
ggplot(mydata, aes(x=our_data)) +
geom_histogram(bins = input$bins)
})
}
# Run the application
shinyApp(ui = ui, server = server)
我已经实现了数据集的创建,但是显示数据直方图的代码返回错误:“object 'mydata' not found”而不是显示直方图。每当任何输入发生更改时,直方图都应该更新。
任何解决问题的帮助将不胜感激。
【问题讨论】: