不可能将 ggvis 与 shiny 一起使用
impossible to use ggvis with shiny
有人能解释一下为什么我的 shiny 应用程序在本地运行良好但无法部署到 shinyapps 吗?
当我将它部署到服务器时,应用程序加载并似乎工作正常,直到它变成灰色并显示一条警告消息“已与服务器断开连接”...
我尝试了不同的数据集,但即使使用这个最小的重现性示例,我也无法使该应用程序运行:/
复制示例:
library(shiny)
library(dplyr)
library(shinydashboard)
library(tidyverse)
library(plotly)
library(ggvis)
ID <- c('A12B5', 'A12B5', 'A12B5','B45F8', 'B45F8', 'B45F8', 'G65V7', 'G65V7', 'G65V7')
YEAR <- c(2016, 2017, 2018, 2016, 2017, 2018, 2016, 2017, 2018)
Indice <- c('A', 'B', 'A', 'A', 'B', 'A', 'A', 'B', 'A')
value <- c(0.41, 0.15, 0.67, 0.12, 0.87, 0.46, 0.35, 0.54, 0.74)
df1 <- data.frame(ID, YEAR, Indice, value)
df1$YEAR<- as.factor(df1$YEAR)
df1$Indice <- as.factor(df1$Indice)
ID <- c('A12B5','B45F8','G65V7')
YEAR <- c(2016, 2017, 2018)
Indice <- c('C', 'C', 'C')
value <- c(4.1, 6.4, 1.45)
df2 <- data.frame(ID, YEAR, Indice, value)
df2$YEAR <- as.factor(df2$YEAR)
ui <- dashboardPage(
dashboardHeader(title ="test"),
dashboardSidebar(
sidebarMenu(
menuItem("test", tabName = "test"))),
dashboardBody(
tabItems(
tabItem(tabName = "test",
fluidRow(style="padding-top:50px;",
column(width = 12, wellPanel(
h4("Selection"),
selectInput(inputId = "ID", label= "ID", choices = sort(unique(df1$ID)),
selected = "A12B5")),
tabBox(type="tabs", width = 12,
tabPanel("Panel 1", ggvisOutput("test_A"), absolutePanel(bottom = 150, right = 20,
radioButtons("Indice", label="variable to plot", choices = c("A", "B"), selected = "A"))),
tabPanel("Panel 2", ggvisOutput("test_B")))))))))
server <- function(input, output){
test_A <- reactive({
df1 %>%
dplyr::filter(ID == input$ID, Indice == input$Indice) %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
add_axis("x", title = "Année", title_offset = 40) %>%
add_axis("y", title = "value", title_offset = 60)
})
test_A %>% bind_shiny("test_A")
test_B <- reactive({
df2 %>%
dplyr::filter(ID == input$ID) %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
add_axis("x", title = "Année", title_offset = 40) %>%
add_axis("y", title = "value", title_offset = 60)
})
test_B %>% bind_shiny("test_B")
}
shinyApp(ui, server)
只需让数据成为反应式并在反应式之外使用 ggvis
,如下所示
server <- function(input, output){
test_A <- reactive({
df1 %>%
dplyr::filter(ID == input$ID, Indice == input$Indice)
})
test_A %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
# add_axis("x", title = "Année", title_offset = 40) %>%
# add_axis("y", title = "value", title_offset = 60) %>%
bind_shiny("test_A","test_A_ui")
test_B <- reactive({
df2 %>%
dplyr::filter(ID == input$ID)
})
test_B %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
# add_axis("x", title = "Année", title_offset = 40) %>%
# add_axis("y", title = "value", title_offset = 60) %>%
bind_shiny("test_B","test_B_ui")
}
shinyApp(ui, server)
有人能解释一下为什么我的 shiny 应用程序在本地运行良好但无法部署到 shinyapps 吗?
当我将它部署到服务器时,应用程序加载并似乎工作正常,直到它变成灰色并显示一条警告消息“已与服务器断开连接”...
我尝试了不同的数据集,但即使使用这个最小的重现性示例,我也无法使该应用程序运行:/
复制示例:
library(shiny)
library(dplyr)
library(shinydashboard)
library(tidyverse)
library(plotly)
library(ggvis)
ID <- c('A12B5', 'A12B5', 'A12B5','B45F8', 'B45F8', 'B45F8', 'G65V7', 'G65V7', 'G65V7')
YEAR <- c(2016, 2017, 2018, 2016, 2017, 2018, 2016, 2017, 2018)
Indice <- c('A', 'B', 'A', 'A', 'B', 'A', 'A', 'B', 'A')
value <- c(0.41, 0.15, 0.67, 0.12, 0.87, 0.46, 0.35, 0.54, 0.74)
df1 <- data.frame(ID, YEAR, Indice, value)
df1$YEAR<- as.factor(df1$YEAR)
df1$Indice <- as.factor(df1$Indice)
ID <- c('A12B5','B45F8','G65V7')
YEAR <- c(2016, 2017, 2018)
Indice <- c('C', 'C', 'C')
value <- c(4.1, 6.4, 1.45)
df2 <- data.frame(ID, YEAR, Indice, value)
df2$YEAR <- as.factor(df2$YEAR)
ui <- dashboardPage(
dashboardHeader(title ="test"),
dashboardSidebar(
sidebarMenu(
menuItem("test", tabName = "test"))),
dashboardBody(
tabItems(
tabItem(tabName = "test",
fluidRow(style="padding-top:50px;",
column(width = 12, wellPanel(
h4("Selection"),
selectInput(inputId = "ID", label= "ID", choices = sort(unique(df1$ID)),
selected = "A12B5")),
tabBox(type="tabs", width = 12,
tabPanel("Panel 1", ggvisOutput("test_A"), absolutePanel(bottom = 150, right = 20,
radioButtons("Indice", label="variable to plot", choices = c("A", "B"), selected = "A"))),
tabPanel("Panel 2", ggvisOutput("test_B")))))))))
server <- function(input, output){
test_A <- reactive({
df1 %>%
dplyr::filter(ID == input$ID, Indice == input$Indice) %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
add_axis("x", title = "Année", title_offset = 40) %>%
add_axis("y", title = "value", title_offset = 60)
})
test_A %>% bind_shiny("test_A")
test_B <- reactive({
df2 %>%
dplyr::filter(ID == input$ID) %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
add_axis("x", title = "Année", title_offset = 40) %>%
add_axis("y", title = "value", title_offset = 60)
})
test_B %>% bind_shiny("test_B")
}
shinyApp(ui, server)
只需让数据成为反应式并在反应式之外使用 ggvis
,如下所示
server <- function(input, output){
test_A <- reactive({
df1 %>%
dplyr::filter(ID == input$ID, Indice == input$Indice)
})
test_A %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
# add_axis("x", title = "Année", title_offset = 40) %>%
# add_axis("y", title = "value", title_offset = 60) %>%
bind_shiny("test_A","test_A_ui")
test_B <- reactive({
df2 %>%
dplyr::filter(ID == input$ID)
})
test_B %>%
ggvis(~YEAR,~value, fill=~Indice) %>%
layer_bars(width = 0.4) %>%
# add_axis("x", title = "Année", title_offset = 40) %>%
# add_axis("y", title = "value", title_offset = 60) %>%
bind_shiny("test_B","test_B_ui")
}
shinyApp(ui, server)