当我在RStudio中运行我的闪亮应用程序时,它运行正常,这是图像: propershiny
但是当我上传它时,它只显示国家/地区列表(以非常简单的方式没有响应性),这里是链接:https://alinapod.shinyapps.io/gendercomposition/来检查。
我的代码是:
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "ctry",
label = "Select countries:",
choices = levels(x$country),
selected = "Switzerland",
multiple = TRUE),
sliderInput(inputId = "year",
label = "Year:",
min = 1996, max = 2016,
value = 1996,
step = 1, animate = TRUE)
),
mainPanel(
plotOutput(outputId = "scatterplot", height = 600),
dataTableOutput(outputId = "datatable")
)
)
)
server <- function(input,output){
output$scatterplot <- renderPlot({
ggplot(data = filter(x, year == input$year & country %in% input$ctry),
aes_string(x = "female", y = "male", color = "region", size = "total_population")) +
geom_point() +
geom_text(data = filter(x, year == input$year & country %in% input$ctry),
aes(label = country), color = "black", size = 4.5, hjust = 0, vjust = -1.5) +
scale_color_manual("Regions", labels = c("AF" = "Africa", "ASIA" = "Asia", "AUS" = "Australia",
"EUR" = "Europe", "LATAM" = "Latin America",
"ME" = "Middle East", "NORAM" = "North America"),
values = c("AF" = "aquamarine3","ASIA" = "firebrick1", "AUS" = "darkorange2",
"EUR" = "dodgerblue3", "LATAM" = "forestgreen",
"ME" = "goldenrod1", "NORAM" = "dodgerblue4")) +
scale_size_continuous("",labels = NULL, breaks = NULL, range = c(2,15)) +
ggtitle("Gender Composition") +
xlab(paste("Female Percentage")) +
ylab(paste("Male")) +
scale_x_continuous(breaks = seq(0,80,10), limits = c(0,80)) +
scale_y_continuous(breaks = seq(0,80,10), limits = c(0,80))
})
output$datatable <- DT::renderDataTable({
req(input$ctry)
selected_countries <- select(filter(x, year == input$year & country %in% input$ctry),
country, female, male, total_population)
DT::datatable(data = selected_countries,
rownames = FALSE)
})
}
shinyApp(ui = ui, server = server)
即使我上传了关于间歇泉的样本闪亮应用,也会发生同样的情况。不知道这里发生了什么。
答案 0 :(得分:1)
只需让您的R脚本显式加载数据,而不是依赖于在全局环境中预加载的对象。否则用户分配或上传的renderPlot
或renderDataTable
中使用的 x 位于何处。您可以阅读ui
和server
来电之上的数据,以避免重复分配:
library(shiny)
library(DT)
library(dplyr)
library(ggplot2)
x <- read.csv('mydata.csv')
# x <- readRDS("mydata.rds")
ui <- ...
server <- ...
shinyApp(ui = ui, server = server)
在从RStudio推送到ShinyApps.io时,请务必使用R脚本检查数据。