С помощью приведенного ниже кода я пытался изменить ось Y для разработки этого графика, но я не совсем уверен, что я делаю. В этом вопросе кажется, что они хотят что-то похожее, но с таблицей данных разница в том, что у них глобальный фрейм данных, мне нужно, чтобы он был reactive
, потому что я хочу, чтобы вся визуализация изменилась, когда я измените этот ввод.
# GLOBAL #
# UI #
ui <- fluidPage(
# Set theme
theme = shinytheme("lumen"),
navbarPage("Analysis",
tabPanel("Impact",
titlePanel(
div(
h1(HTML(paste0("<b>","Graph against cluster count","</b>"))),
align = "left"
)
),
tags$br(),
fluidRow(
sidebarPanel(
hr(style="border-color: #606060;"),
h3(HTML(paste0("<b>","Clusters impact.","</b>"))),
h5("Key areas of patent concentration can be found around the clusters that reach higher levels."),
br(),
# Y axis selection
radioButtons("y_axis",
h4("What do you want to analyze IP collection against?"),
choices = list("Claims" = 3,
"Forward citations" = 4,
"Backward citations" = 5,
"Patent Strenght mean" = 6),
selected = 3), # radioButtons - y_axis
hr(style="border-color: #606060;"),
width = 3
),
mainPanel(
br(),
plotlyOutput("impact"),
br(),
width = 9
)
)
)
)
)
# SERVER #
server <- function(input, output, session) {
# Set maximun input size as 100Mb
options(shiny.maxRequestSize=100*1024^2)
# Plot
## Data setting
dtd5 <- reactive({
dtd5 <- structure(list(Topic = c("Topic 1", "Topic 3", "Topic 5", "Topic 9"),
Count = c(45L, 51L, 40L, 32L),
Claims = c(630, 346, 571, 599),
Forward = c(64, 32, 27, 141),
Backward = c(266, 177, 101, 397),
`Strength mean` = c(31, 25.22, 30.85, 39.59)),
row.names = c(NA, -4L), class = "data.frame")
dtd5 <- as.data.frame(dtd5)
})
## Visualization
output$impact <- renderPlotly({
# Color setting
ramp4 <- colorRamp(c("darkred", "snow3"))
ramp.list4 <- rgb( ramp4(seq(0, 1, length = 15)), max = 255)
# Scatterplot
y <- dtd5()[,input$y_axis]
p <- ggplot(dtd5(), aes(x=Count, y=y) ) +
geom_point(aes(col=Topic)) +
labs(y=colnames(dtd5())[input$y_axis],
x="Cluster count",
title="Cluster Impact") +
theme_minimal() +
scale_colour_manual(values=ramp.list4)
ggplotly(p) %>%
config(displayModeBar = FALSE)
})
}
shinyApp(ui,server)
В консоли он выводит этот вывод, так что я уверен, что структура работает хорошо, но получение его внутри приложения - вот что происходит.
dtd5 <- structure(list(Topic = c("Topic 1", "Topic 3", "Topic 5", "Topic 9"
), Count = c(45L, 51L, 40L, 32L), Claims = c(630, 346, 571, 599
), Forward = c(64, 32, 27, 141), Backward = c(266, 177, 101,
397), `Stregth mean` = c(31, 25.22, 30.85, 39.59)), row.names = c(NA,
-4L), class = "data.frame")
# Scatterplot
y <- dtd5[,4]
p <- ggplot(dtd5, aes(x=Count, y=y) ) +
geom_point(aes(col=Topic)) +
labs(y=colnames(dtd5)[4],
x="Number of patents",
title="Cluster Impact") +
theme_minimal()
ggplotly(p) %>%
config(displayModeBar = FALSE)
В этом другом вопросе они, кажется, тянут его подобно тому, что я сделал, но он продолжает печатать эту ошибку:
Listening on http://127.0.0.1:7465
Warning: Error in [.data.frame: undefined columns selected
[No stack trace available]
Извините, если это слишком просто, но