【发布时间】:2020-05-26 18:03:57
【问题描述】:
当我尝试将 tableOutput 或 DTOutput 编码到我的 Shiny 应用程序中时,我收到“错误:找不到函数“daysSince10””。
我试过 validate(need()) 和 require()。任何想法为什么这不起作用?
library(shiny)
library(tidyverse)
daysSince10 <- read_csv("https://raw.githubusercontent.com/joegoodman94/CoronavirusTracker/master/days10.csv")
ui <- fluidPage(
titlePanel("Coronavirus Tracker"),
sidebarLayout(
sidebarPanel(selectInput('Country', 'Select Country', multiple = T, unique(daysSince10$`Country`))),
mainPanel(
tabsetPanel(
tabPanel("Plot", plotly::plotlyOutput('trend')),
tabPanel("Table", DT::DTOutput('table'))
)
)
)
)
server <- function(input, output, session) {
observe({
moddays <- daysSince10[daysSince10$`Country` %in% input$Country,]
output$trend <- plotly::renderPlotly({
validate(
need(input$Country, "please select a country")
)
ggplot(moddays) +
geom_line(aes(x = `Days since tenth death`, y = `Total Deaths`, color = `Country`)) +
scale_y_log10()
})
output$table <- DT::renderDT({
validate(
need(input$Country, "please select a country")
)
daysSince10()
})
})
}
shinyApp(ui = ui, server = server)
【问题讨论】: