R 我需要什么条件才能使我的情节反应?

R 我需要什么条件才能使我的情节反应?,r,ggplot2,shiny,plotly,reactive,R,Ggplot2,Shiny,Plotly,Reactive,我试着使用我的数据框,它有一个列名“release_year”作为滑块输入,所以无论我选择什么时间线,比如说1960年到1970年,我都只能在散点图上看到特定时间线的数据。现在我的滑杆动作很奇怪,除了移动几点之外什么都没做。我怎样才能解决这个问题?像这样的 你看到年度发布滑块了吗?我要的正是那件事 附加我的数据集的图像 [df]() 结构(列表id=c(135397L、135397L、76341L、76341L、262500L、, 140607L、140607L、140607L、168259L

我试着使用我的数据框,它有一个列名“release_year”作为滑块输入,所以无论我选择什么时间线,比如说1960年到1970年,我都只能在散点图上看到特定时间线的数据。现在我的滑杆动作很奇怪,除了移动几点之外什么都没做。我怎样才能解决这个问题?像这样的 你看到年度发布滑块了吗?我要的正是那件事

  • 附加我的数据集的图像
  • [df]()

    结构(列表id=c(135397L、135397L、76341L、76341L、262500L、, 140607L、140607L、140607L、168259L、168259L),预算=c(150000000L, 150000000升,150000000升,150000000升,110000000升,2000000000升,2000000000升, 2000000000L,190000000L,190000000L),收入=c(1513528810, 1513528810, 378436354, 378436354, 295238201, 2068178225, 2068178225, 2068178225,1506249360,1506249360),标题=结构(c(3L, 3L,4L,4L,2L,5L,5L,5L,1L,1L),标签=c(“狂暴7”, 《叛乱分子》、《侏罗纪世界》、《疯狂麦克斯:狂暴之路》、《星球大战:原力觉醒》 ),class=“factor”),主页=结构(c(2L,2L,3L,3L, 5L,4L,4L,4L,1L,1L),标签=c(“http://www.furious7.com/", "http://www.jurassicworld.com/", "http://www.madmaxmovie.com/", "http://www.starwars.com/films/star-wars-episode-vii", "http://www.thedivergentseries.movie/#insurgent" ),class=“factor”),director=结构(c(1L,1L,2L,2L, 5L,3L,3L,3L,4L,4L),.Label=c(“科林·特雷沃罗”,“乔治·米勒”, “J.J.艾布拉姆斯”、“詹姆斯·万”、“罗伯特·施文特克”),class=“factor”), 运行时=c(124L,124L,120L,120L,119L,136L,136L,136L, 137L,137L),投票平均=c(6.5,6.5,7.1,7.1,6.3,7.5, 7.5,7.5,7.3,7.3),发布年份=c(2015L,2015L,2015L, 2015L,2015L,2015L,2015L,2015L,2015L,2015L),体裁=结构(c(1L, 2L、1L、2L、2L、1L、2L、4L、1L、3L),.Label=c(“操作”, “冒险”,“犯罪”,“幻想”,class=“factor”),盈亏平衡=c(1363528810, 1363528810, 228436354, 228436354, 185238201, 1868178225, 1868178225、1868178225、1316249360、1316249360),AerageVotesCat=结构(c(2L, 2L、2L、2L、2L、1L、1L、1L、1L、1L),标签=c(“优秀”, “好”),class=“factor”)),row.names=c(NA,10L),class=“data.frame”
  • [需要控制显示数据的滑块]()

我几乎花了一个星期的时间尝试了所有的事情。我似乎无法解决这个问题。我知道问题就在我处于被动状态的某个地方?但作为一个新手,我不知道该传递什么

UI:
library(gifski)
library(gganimate)
library(dplyr)
library(DT)
library(shinythemes)
library(scales)
library(shiny)
library(ggplot2)
library(plotly)



df <- read.csv("C:/Users/XXX/Downloads/movie1.csv")
n_total <- nrow(df)

ui <- fluidPage(theme = shinytheme("united"),
                titlePanel("Movie browser, 1960 - 2014", windowTitle = "Movies"),   

                # Sidebar layout with a input and output definitions
                sidebarLayout(
                  # Inputs
                  sidebarPanel(
                    wellPanel(

                      # Select variable for y-axis
                      selectInput(inputId = "y", 
                                  label = h4("Y-axis:"),
                                  choices =c("Budget" ="budget", "Revenue" = "revenue", "Runtime" = "runtime", "Vote average" = "vote_average", "Year released" = "release_year", "Profit" = "breakeven"), 
                                  selected = "revenue"),

                  sliderInput("SectorTime", h4("Select a time period:"), min = 1960, max = 2015,
                                value = c(1960,2015), step = 5),


                    textInput("Director", h4("Director name contains (e.g., Miyazaki)")),
                    numericInput(inputId = "n",
                                 label = h4("Sample size:"),
                                 value = 30,
                                 min = 1, max = n_total,
                                 step = 1),


                    radioButtons(inputId = "filetype",
                                 label = "Select filetype:",
                                 choices = c("csv", "tsv"),
                                 selected = "csv"),

                    # Select variables to download
                    checkboxGroupInput(inputId = "selected_var",
                                       label = "Select variables:",
                                       choices = names(df),
                                       selected = c("title"))
                  ),

                  # Outputs
                  mainPanel(
                    tabsetPanel(
                      tabPanel(h4("PLOT"), plotlyOutput("plot"),
                                            tabPanel(h4("DATA"), DT::dataTableOutput(outputId = "moviestable", width = 500)






                  )
                )
)
UI:
图书馆(吉夫斯基)
库(gganimate)
图书馆(dplyr)
图书馆(DT)
图书馆(shinythemes)
图书馆(比例尺)
图书馆(闪亮)
图书馆(GG2)
图书馆(绘本)

df您的问题是错误地使用了
sample
:第二个参数通常是样本大小,而不是要从中筛选的字段。考虑到您的数据,它应该可以用于:


dataset您的问题是错误地使用了
sample
:第二个参数通常是样本大小,而不是要从中筛选的字段。给定您的数据,它应该可以用于:


dataset Hasan,请研究一下如何以一种有帮助的方式提问。StackOverflow的索引页特别指出“对数据使用
dput()
,并使用
library()
调用指定所有非基本包。不要为数据或代码嵌入图片,而是使用缩进的代码块。”因此,请尽可能多地(包括我)使用dput(头(x))
不会将数据图像转录到要测试的内容中。其他参考文献:,和…但我的第一个猜测是让您阅读
sample
的第二个参数的作用。它不会猜测您希望对特定列的数据行进行采样,以在其中包含一个或多个值。可能需要替换
sample(nrow(df),input$SectorTime),]
with
df[df$yr>=input$SectorTime[1]&df$yr您好。抱歉。我正在整理我的数据。您提到的这段代码给了我一个空白输出。所以只是一个白色屏幕它可能会显示一个白色屏幕,因为我不知道您的年份列的名称(既然您提供了数据,我看到它是
$release\u year
)。我使用了
$yr
作为占位符。你改变了它,但它仍然失败了吗?太棒了!Works!在过去的一周里一直在这个问题上。Gracias!Hasan,请研究一下如何以一种有帮助的方式提问。StackOverflow的索引页上特别写着“使用
dput()
用于数据,并使用
library()
调用指定所有非基本包。不要为数据或代码嵌入图片,而是使用缩进的代码块。“。因此,请尽可能多地使用
dput(头(x))
(包括我)不会将数据图像转录到要测试的内容中。其他参考文献:,和…但我的第一个猜测是让您阅读
sample
的第二个参数的作用。它不会猜测您希望对特定列的数据行进行采样,以在其中包含一个或多个值。可能需要替换
sample(nrow(df),input$SectorTime),]
with
df[df$yr>=input$SectorTime[1]&df$yr您好。抱歉。我正在整理我的数据。您提到的这段代码给了我一个空白输出。所以只是一个白色屏幕它可能会显示一个白色屏幕,因为我不知道您的年份列的名称(既然你提供了数据,我知道它是
$release\u year
)。我用了
$yr
作为占位符。你改变了它,它仍然失败了吗?太棒了!工作!在过去的一周里一直停留在这个问题上。Gracias!最后一个问题我如何使用我的textinput“director”要筛选出我的数据帧?例如,通过在控制器名称中计时,DF会自动更新到闪亮的位置!
…&(DF$director==“”| DF$director==input$director)
?服务器中类似的内容?
输出$moviestable%选择(标题:Ae
SERVER:

# Define server function required to create the scatterplot
server <- function(input, output) {

  dataset <- reactive({
    df[sample(nrow(df), input$SectorTime),]
  })


  # Create scatterplot object the plotOutput function is expecting
  output$plot <- renderPlotly({
    point <- format_format(big.mark = " ", decimal.mark = ",", scientific = FALSE)


    p <- ggplot(data = dataset(), aes_string(x = input$x, y = input$y, col = input$z)) +
      geom_point(alpha = input$alpha, size = 2, shape = 1)  +  theme_minimal() +
      ggtitle("Scatter plot between various variables") +scale_x_continuous(labels = point) + scale_y_continuous(labels = point)
    p +  theme(axis.text.x = element_text(angle = 30)) 

  })
   output$moviestable <- DT::renderDataTable({
    movies_sample <- df %>%
      sample_n(input$n) %>%
      select(title: AerageVotesCat)
    DT::datatable(data = movies_sample, 
                  options = list(pageLength = 30), 
                  rownames = FALSE)
  })

 }

# Create the Shiny app object
shinyApp(ui = ui, server = server)