最初のselectInput
ウィジェットでデータセットを変更すると、誰にエラーが表示されるのですか? diamonds
からmtcars
にデータセットを変更すると、エラーCould not find 'carat'
がinput$bins
になり、プロットでは1秒間しか表示されず、すべて正常に機能します。それはなぜ起こったのですか?光沢のある反応入力の警告を削除するには
library(shiny)
library(ggplot2)
data(diamonds)
data(mtcars)
ui <- fluidPage(
column(3,
selectInput("data", "", choices = c('mtcars', 'diamonds')),
uiOutput('server_cols'),
uiOutput('server_bins')
),
column(9,
plotOutput("plot")
)
)
server <- function(input, output) {
data <- reactive({
switch(input$data,
diamonds = diamonds,
mtcars = mtcars)
})
output$server_cols <- renderUI({
data <- data()
nam <- colnames(data)
selectInput('cols', "Choose numeric columns:", choices = nam[sapply(data, function(x) is.numeric(x))])
})
output$server_bins <- renderUI({
if (!is.null(input$cols)) {
df <- data()
x <- eval(input$cols)
max_value <- max(df[,x])
sliderInput('bins','Choose number of bins:', min = 0.1,
max = max_value,
value = max_value/2)
}
})
output$plot <- renderPlot({
if (!is.null(input$cols) & !is.null(input$bins)) {
basicData <- data()
var <- eval(input$cols)
ggplot(basicData, aes_string(var)) +
geom_histogram(binwidth = input$bins, color = 'white', fill = 'red')
}
})
}
shinyApp(ui, server)
'carat'は' diamonds'データセットのカラム名です。 'mtcars'データセットを見てそこからカラム名を選ぶことができます。 –
私は何が起こったのか理解しています。しかし、私はこの警告を避ける方法を知らない。 – Nicolabo